I have a test
folder the structure within the folder
__init.py__
aa.py
test.py
for aa.py
class aa:
def __init__(self,max):
self.max=max
print max+1
def hello(self):
print(max)
for test.py
import aa
abc = aa(100)
abc.hello()
when run test.py
, I have an error
abc = aa(100)
TypeError: 'module' object is not callable
What is the problem?
You have a module aa
, and in that module you have a class aa
. You only import the module.
Either do:
import aa
abc = aa.aa(100)
or:
from aa import aa
abc = aa(100)
or, even better, use separate names for module and class.
you need to do like this.
from aa import aa
abc = aa(100)
abc.hello()
使用from aa import *
代替test.py
脚本中的import aa
。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.