首页 > Web开发 > 详细

TypeError: 'module' object is not callable cp fromhttp://blog.csdn.net/huang9012/article/details/17417133

时间:2015-12-16 21:13:30      阅读:249      评论:0      收藏:0      [点我收藏+]

程序代码 
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

TypeError: 'module' object is not callable cp fromhttp://blog.csdn.net/huang9012/article/details/17417133

原文:http://www.cnblogs.com/wswang/p/5052279.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!