TypeError: 'module' object is not callable 原因分析
来源:互联网 发布:c语言编写99乘法表三角 编辑:程序博客网 时间:2024/05/10 15:31
程序代码
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
- 【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
- 通用测试用例补充
- Java compiler level does not match the version of the installed Java project facet
- 《深入理解Windows操作系统》笔记5
- eclipse添加project(英文版,中文也适用)
- 语法文件的写法
- TypeError: 'module' object is not callable 原因分析
- C# 添加,修改,删除文件夹/文件集合
- Delaunay三角形网格
- adb 远程访问
- 跨越信息沟通的障碍,构建企业高效应用平台
- [extjs]GridPanel中表头checkbox全选框的bug
- Perl如何从url安装package
- 2012新的一年
- 自定义语言分析器写法示例 .jjt