Python中模块导入时遇到的问题
初学python,在python中导入模块时,遇到一个问题:’module’ object is not callable
在目录D:\Python\Python35-32\MyWork\PythonBasic\misc下,创建了一个类Student,保存为Student.py,然后将该类作为一个python模块导入。
import sys
sys.path.append(r'D:\Python\Python35-32\MyWork\PythonBasic\misc') #经过之后可以使用该目录下自己编写的模块
import Student
程序运行到这里没有毛病,此时;接着在python shell里编写:
>>> st = Student()
Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
st = Student()
TypeError: 'module' object is not callable
>>>
错误出现了:’module’ object is not callable
解决办法:
一、使用 模块名.类()的方式调用
>>> st = Student.Student()
>>>
这样使用时没有毛病的。
二、在导入模块的时候,将import Student 修改为 from Student import *
>>> from Student import *
>>> st = Student()
>>>
这样使用,也没有毛病!初学,处处是坑。。