程序代码
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
=============下面这个解法更能体现问题所在,就是模块的路径问题
问题:
我不能确定我为什么得到这个错误:
- ****************************************************************
-
Traceback(mostrecentcalllast):
-
File "my.py" ,line
3 , in ?
-
urlparse( 'http://www.cwi.nl:80/%7Eguido/Python.html')
-
TypeError: 'module' objectis
not callable
-
**************************************************
源代码如下:
-
import urlparse
-
-
urlparse( 'http://www.cwi.nl:80/%7Eguido/Python.html')
答复:
"TypeError: 'module' object is not callable"这个信息是说你试图把"urlparse"这个模块作为一个函数来调用,但它却无法调用。
urlparse这个模块包含urlparse和 urlsplit等函数。我把urlsplit也拖了进来,它的名字和模块名不同。这个可能能帮助你发现问题。以下是调用它们的两种方法。
(1)
-
>>> import urlparse
-
>>>urlparse.urlparse( 'http://www.cwi.nl:80/%7Eguido/Python.html')
-
( 'http' ,
'www.cwi.nl:80' , '/%7Eguido/Python.html',
'' , ''
, '' )
-
>>>urlparse.urlsplit( 'http://www.cwi.nl:80/%7Eguido/Python.html')
-
( 'http' ,
'www.cwi.nl:80' , '/%7Eguido/Python.html',
'' , ''
)
-
>>>
(2)
-
>>> from urlparse
import urlparse,urlsplit
-
>>>urlparse( 'http://www.cwi.nl:80/%7Eguido/Python.html')
-
( 'http' ,
'www.cwi.nl:80' , '/%7Eguido/Python.html',
'' , ''
, '' )
-
>>>urlsplit( 'http://www.cwi.nl:80/%7Eguido/Python.html')
-
( 'http' ,
'www.cwi.nl:80' , '/%7Eguido/Python.html',
'' , ''
)
-
>>>
方法1可能更适合你。
分享到:
相关推荐
主要介绍了Django 错误:TypeError at / 'bool' object is not callable解决,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
Python 出现错误TypeError: ‘NoneType’ object is not iterable解决办法 TypeError: ‘NoneType’ object is not iterable 这个错误提示一般发生在将None赋给多个值时。 def myprocess(): a == b if a != b: ...
TypeError: 'list' object is not callable 刚开始学习python的时候,可能会由于命名的不注意,导致也方法一直用不了,原因是在声明变量对的时候和python内置方法冲突了,导致方法被重新定义了,这样一来,方法自然...
资源(241条消息)Python中报错“TypeError:‘list‘objectisnotcallable”的解决方法知识分享
主要介绍了解决Python中报错TypeError: must be str, not bytes问题,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
翻译过来是类型为“type”的TypeError对象没有len(),我报错的代码是: #coding=utf-8 print(请输入一个字符串:) a = input('') #回文的长度至少为2 if len(str) < 2: print('请不要输入空字符串!') a = ...
TypeError: notify.sendNotifybyWxPucher is not a function!
本文研究的主要是Python使用pickle模块存储数据报错解决方法,以代码的形式展示,具体如下。 首先来了解下pickle模块 pickle提供了一个简单的持久化功能。...TypeError: write() argument must be str, not byte
生成位图字体的中英文字符
补充知识:TypeError: cannot concatenate ‘str’ and ‘list’ objects和Python读取和保存图片 运行程序时报错,然后我将list转化为str就好了。 利用”.join(list) 如果需要用逗号隔开,如1,2,3,4则使用’,’....
TypeError: loop of ufunc does not support argument 0 of type Tensor which has no callable arctan method 报错行 self.u = np.round(np.dot(self.F, self.u)) #或者 self.u = np.round(self.u + np.dot(K, ...
主要介绍了Vue 报错TypeError: this.$set is not a function 的解决方法,分享给大家,需要的朋友们下面随着小编来一起学习学习吧
问题描述 因为numpy的int类型无法被json化,所以需要将numpy的int转为原生类型。 解决方案 # pandas返回的 sex_cnt = marks['sex'].value_counts() type(sex_cnt['男']) # numpy.int64 # 3种转化方法 ...
主要介绍了Python BeautifulSoup [解决方法] TypeError: list indices must be integers or slices, not str,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着...
TypeError at / 'bool' object is not callable 编写函数如下: def index(request, pid=None, del_pass=None): if request.user.is_authenticated(): username = request.user.username useremail = request....
1.需要node环境支持 2.下载模拟器->微信->搜索你要扒取的小程序(点开即可) 3.打开RE文件管理器,获取root权限,从根目录开始。... 4.执行反编译命令,node wuWxapkg.js filepath 百度也有很多教程,基本大致相同,...
学习《Python数据分析基础》第3章最后一个例子:为每个工作簿和工作表计算总数和均值时,在pandas 实现这个例子中的data 处...TypeError, ‘int’ object is not iterable 原创文章 36获赞 28访问量 4万+ 关注 私信
今天用execjs调用JS时,发现报错execjs._exceptions.ProgramError: ReferenceError: document is not defined 如图: 错误类型:文档对象未定义,解决方法,定义对象即可,习惯性定义变量嘛 var document ;? ...