python 3.5 raiaing an error when import the class Manager in this module sayning name Manager is not define
Peter Otten
__peter__ at web.de
Wed Jul 12 11:55:54 EDT 2017
WoFy The 95s wrote:
> On Wednesday, 12 July 2017 18:57:11 UTC+5:30, Peter Otten wrote:
>> WoFy The 95s wrote:
>>
>> > i tried from idle interpreter
>> >
>> > from person import Manager
>> >
>> >
>> >
>> >>>> from person import Manager
>> > Traceback (most recent call last):
>> > File "<pyshell#95>", line 1, in <module>
>> > from person import Manager
>> > ImportError: cannot import name 'Manager'
>>
>>
>> Enter
>>
>> import person
>> person.__file__
>>
>> in idle's shell. There may be another file called person.py which is
>> imported instead of the one you intended.
>>
>>
>> > and this also
>> >>>> import person
>> >
>> >>>> tom = Manager('parias lunkamaba', 'mgr', 500000)
>> >
>> > then i get this
>> >
>> >
>> > Traceback (most recent call last):
>> > File "<pyshell#92>", line 1, in <module>
>> > tom=Manager('Tome Jones', 'mgr', 50000)
>> > NameError: name 'Manager' is not defined
>>
>> This is standard behaviour. If after
>>
>> import person
>>
>> you want to access a name in the person module you have to use the
>> qualified name, e. g.
>>
>> tom = person.Manager('parias lunkamaba', 'mgr', 500000)
>
>
>
>>>>import person
>>>>tom = person.Manager('Parias lunkamba', 'mgr', 500000)
>>>>Traceback (most recent call last):
> File "<pyshell#125>", line 1, in <module>
> tom = person.Manager('parias lunkamba', 'mgr', 500000)
> AttributeError: module 'person' has no attribute 'Manager'
>
> why the module in python 3.5 doesn't recognize the Manager class?
Again, you probably have two files called person.py, and the one you import
does not contain a Manager class. (Different directories in sys.path can
explain why different person.py files will be imported in differing python
versions)
As I said, you can find out the file's location with
>>> person.__file__
or have a look at the module content with
>>> import inspect
>>> import person
>>> print(inspect.getsource(person))
More information about the Python-list
mailing list