python callable错误_python错误:TypeError: 'module' object is not callable 解决方法

python错误:TypeError: 'module' object is not callable 解决方法

发布于 2014-12-08 16:49:36 | 16689 次阅读 | 评论: 1 | 来源: PHPERZ

Python编程语言Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。

本文为大家讲解的是python错误:TypeError: 'module' object is not callable 解决方法,感兴趣的同学参考下。

错误描述:

程序代码

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 "", line 1, in

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

相关阅读:

python错误:TypeError: 'module' object is not callable 解决方法

Python错误:TypeError: 'str' object is not callable原因分析

Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法

python错误:AttributeError: 'module' object has no attribute 'setdefaultencoding'解决方法

Python安装Imaging报错:The _imaging C module is not installed解决方法

python程序报错 IOError: decoder zip not available解决方法

Python中str is not callable问题详解及解决办法

Python首次安装后运行报错(0xc000007b)的解决方法

Python安装PIL库提示:Python version 2.7 required, which was not found in the registry错误的解决方法

python安装错误:UnicodeDecodeError: 'ascii' codec can't decode byte解决方法

Python安装第三方库报错:Python version 2.7 required, which was not found in the registry.解决方法

MySQL-python-1.2.4b4.win32-py2.7安装报错:python version 2.7 required,which was not found in the registry.解决方法

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值