TypeError: 'module' object is not callable
John Machin
sjmachin at lexicon.net
Fri Apr 28 03:29:21 EDT 2006
On 28/04/2006 5:05 PM, Gary Wessle wrote:
> 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: 'module' object is not callable
> ****************************************************************
>
> with this code
>
> ****************************************************************
> import urlparse
>
> urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')
> ****************************************************************
The message "TypeError: 'module' object is not callable" means that the
"urlparse" that you are trying to call as a function is a module and is
thus not callable.
The module urlparse contains functions urlparse and urlsplit, among
others. I'm dragging urlsplit into the arena as its name is not the same
as the module 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 Modules section in the tutorial:
http://docs.python.org/tut/node8.html
*and* all the earlier sections if you haven't already.
More information about the Python-list
mailing list