TypeError: 'module' object is not callable 原因分析
来源:互联网 发布:2015年出境游数据 编辑:程序博客网 时间:2024/06/03 19:24
程序代码
class Person:
#constructor
def __init__(self,name,sex):
self.Name = name
self.Sex = sex
def ToString(self):
return 'Name:'+self.Name+',Sex:'+self.Sex
在IDLE中报错:
>>> import Person
>>> per = Person('dnawo','man')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
per = Person('dnawo','man')
TypeError: 'module' object is not callable
原因分析:
Python导入模块的方法有两种:import module 和 from module import,区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要。
正确的代码:
>>> import Person
>>> person = Person.Person('dnawo','man')
>>> print person.Name
或
>>> from Person import *
>>> person = Person('dnawo','man')
>>> print person.Name
class Person:
#constructor
def __init__(self,name,sex):
self.Name = name
self.Sex = sex
def ToString(self):
return 'Name:'+self.Name+',Sex:'+self.Sex
在IDLE中报错:
>>> import Person
>>> per = Person('dnawo','man')
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
per = Person('dnawo','man')
TypeError: 'module' object is not callable
原因分析:
Python导入模块的方法有两种:import module 和 from module import,区别是前者所有导入的东西使用时需加上模块名的限定,而后者不要。
正确的代码:
>>> import Person
>>> person = Person.Person('dnawo','man')
>>> print person.Name
或
>>> from Person import *
>>> person = Person('dnawo','man')
>>> print person.Name
0 0
- 【Python】TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- 【python系列】TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析
- 【Python】TypeError: 'module' object is not callable 原因分析
- TypeError: 'module' object is not callable 原因分析(python模块导入注意事项)
- TypeError: 'module' object is not callable
- TypeError: 'module' object is not callable
- 详细分析Hibernate的merge()方法
- 天梯匹配算法的思路
- 第3章40题
- iOS Crash 分析(文二)-崩溃日志组成
- 鼠标事件-鼠标位置和鼠标滚轮
- TypeError: 'module' object is not callable 原因分析
- Tomcat
- 黑马程序员——java基础—单例设计模式
- iOS Crash 分析(文三)- 符号化崩溃日志
- android:descendantFocusability用法简析
- 开博文
- Android Network --------------关于Android自带的org.apache.http和apache官方的(第三方的)HttpClient的问题
- javascript 容易误解的地方
- ASP.NET FTP