TypeError: 'module' object is not callable cp fromhttp://blog.csdn.net/huang9012/article/details/17417133
2016-01-08 12:24
597 查看
程序代码
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
相关文章推荐
- LSI MegaRAID创建RAID10
- 数论 - 119. Magic Pairs
- sendmail发邮件报错的解决办法
- 【LeetCode】217. Contains Duplicate(sort,hash,map)
- main处理命令行选项
- RAID磁盘阵列学习笔记
- 在这五件事情上,人工智能比人类更出色
- AIDL实现服务跨进程通信
- HDU Fibonacci Again
- 将baidu地图中的baidu logo去掉
- LeetCode: 013-Climbing Stairs
- 又是一家人工智能公司:苹果收购Emotient
- Dell R720 4块硬盘,两块做普通盘,两块做Raid0 安装
- 记一次DG搭建过程中ORA-09925: Unable to createaudit trail file 错误
- 理解assign,copy,retain变strong
- http://blog.csdn.net/shirdrn/article/details/6270506
- K8S中pod在挂载volume时出现FailedMount错误(exit status 32)
- Daily Scrum – 1/7
- rails中的健壮参数
- (总结)密码破解之王:Ophcrack彩虹表(Rainbow Tables)原理详解(附:120G彩虹表下载)