发布网友 发布时间:2024-09-27 18:21
共1个回答
热心网友 时间:2024-10-18 14:49
"TypeError: 'mole' object is not callable"这个信息是说你试图把"urlparse"这个模块作为一个函数来调用,但它却无法调用。
urlparse这个模块包含urlparse 和 urlsplit等函数。我把urlsplit也拖了进来,它的名字和模块名不同。这个可能能帮助你发现问题。以下是调用它们的两种方法。
解决方法:需要输入以下代码。
dear python users
I am not sure why I am getting
************************************************** **************
Traceback (most recent call last):
File "my.py", line 3, in ?
urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')
TypeError: 'mole' object is not callable
************************************************** **************
with this code
************************************************** **************
import urlparse
urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')
************************************************** **************
thank you
Gary Wessle
reply:
The message "TypeError: 'mole' object is not callable" means that the
"urlparse" that you are trying to call as a function is a mole and is
thus not callable.
The mole urlparse contains functions urlparse and urlsplit, among
others. I'm dragging urlsplit into the arena as its name is not the same
as the mole name, and it might help you see what is happening. There
are two ways of calling them:
(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', '', '')
>>>
Method (1) is probably better for you at the moment.
I suggest that you read the Moles section in the tutorial:
http://docs.python.org/tut/node8.html
*and* all the earlier sections if you haven't already.
John Machin