I'm studying classes and OO in python and I found a problem when I try import a class from a package. The project structure and the classes are described below:
ex1/
__init__.py
app/
__init__.py
App1.py
pojo/
__init__.py
Fone.py
The classes:
Fone.py
class Fone(object):
def __init__(self,volume):
self.change_volume(volume)
def get_volume(self):
return self.__volume
def change_volume(self,volume):
if volume >100:
self.__volume = 100
elif volume <0:
self.__volume = 0
else:
self.__volume = volume
volume = property(get_volume,change_volume)
App1.py
from ex1.pojo import Fone
if __name__ == '__main__':
fone = Fone(70)
print fone.volume
fone.change_volume(110)
print fone.get_volume()
fone.change_volume(-12)
print fone.get_volume()
fone.volume = -90
print fone.volume
fone.change_volume(fone.get_volume() **2)
print fone.get_volume()
When I try use from ex1.pojo import Fone, the following Error is raised:
fone = Fone(70)
TypeError: 'module' object is not callable
But when I use from ex1.pojo.Fone import *, the program runs fine.
Why I can't import the Fone class with the way I've coded?