TypeError: 'module' object is not callable

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Gary Wessle

    #1

    TypeError: 'module' object is not callable

    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')
    *************** *************** *************** *************** ****


    thank you
  • John Machin

    #2
    Re: TypeError: 'module' object is not callable

    On 28/04/2006 5:05 PM, Gary Wessle wrote:[color=blue]
    > 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')
    > *************** *************** *************** *************** ****[/color]

    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)[color=blue][color=green][color=darkred]
    >>> import urlparse
    >>> urlparse.urlpar se('http://www.cwi.nl:80/%7Eguido/Python.html')[/color][/color][/color]
    ('http', 'www.cwi.nl:80' , '/%7Eguido/Python.html', '', '', '')[color=blue][color=green][color=darkred]
    >>> urlparse.urlspl it('http://www.cwi.nl:80/%7Eguido/Python.html')[/color][/color][/color]
    ('http', 'www.cwi.nl:80' , '/%7Eguido/Python.html', '', '')[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    (2)[color=blue][color=green][color=darkred]
    >>> from urlparse import urlparse, urlsplit
    >>> urlparse('http://www.cwi.nl:80/%7Eguido/Python.html')[/color][/color][/color]
    ('http', 'www.cwi.nl:80' , '/%7Eguido/Python.html', '', '', '')[color=blue][color=green][color=darkred]
    >>> urlsplit('http://www.cwi.nl:80/%7Eguido/Python.html')[/color][/color][/color]
    ('http', 'www.cwi.nl:80' , '/%7Eguido/Python.html', '', '')[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    Method (1) is probably better for you at the moment.

    I suggest that you read the Modules section in the tutorial:


    *and* all the earlier sections if you haven't already.

    Comment

    Working...