Re: list to tuple and vice versa

Discussion in 'Python' started by Jabba Laci, Oct 18, 2009.

  1. Jabba Laci

    Jabba Laci Guest

    >> The error message is: "TypeError: 'tuple' object is not callable".
    >
    > You created a variable named "tuple" somewhere, which is shadowing the
    > built-in type. Rename that variable to something else.


    Right, it was my bad. After removal the tuple() function works perfectly.

    Thanks,

    Laszlo
     
    Jabba Laci, Oct 18, 2009
    #1
    1. Advertising

  2. Jabba Laci

    StarWing Guest

    On 10月18æ—¥, 下åˆ12æ—¶19分, Ben Finney <> wrote:
    > Jabba Laci <> writes:
    > > Right, it was my bad. After removal the tuple() function works
    > > perfectly.

    >
    > Note that, though it is callable, ‘tuple’ is not a function but a type:
    >
    >     >>> tuple
    >     <type 'tuple'>
    >     >>> len
    >     <built-in function len>
    >
    > You can use the built-in ‘type’ type to get the type of any object:
    >
    >     >>> foo = 12
    >     >>> type(foo)
    >     <type 'int'>
    >     >>> bar = 1, 2, 3
    >     >>> type(bar)
    >     <type 'tuple'>
    >     >>> type(tuple)
    >     <type 'type'>
    >     >>> type(len)
    >     <type 'builtin_function_or_method'>
    >     >>> type(type)
    >     <type 'type'>
    >
    > --
    >  \      “Pinky, are you pondering what I'm pondering?†“Uh, I think so |
    >   `\  Brain, but this time, you wear the tutu.†—_Pinky and The Brain_ |
    > _o__)                                                                  |
    > Ben Finney


    A type is always callable. call a type will call its __init__ special
    method (or and __new__ special method together).
     
    StarWing, Oct 18, 2009
    #2
    1. Advertising

  3. Jabba Laci

    StarWing Guest

    On 10月18æ—¥, 下åˆ1æ—¶32分, Ben Finney <> wrote:
    > StarWing <> writes:
    > > On 10月18æ—¥, 下åˆ12æ—¶19分, Ben Finney <> wrote:
    > > > Jabba Laci <> writes:
    > > > > Right, it was my bad. After removal the tuple() function works
    > > > > perfectly.

    >
    > > > Note that, though it is callable, ‘tuple’ is not a function but a
    > > > type:

    >
    > > A type is always callable.

    >
    > Yes (modulo perversions like explicitly making a non-callable type).
    > This matches what I said above.
    >
    > > call a type will call its __init__ special method (or and __new__
    > > special method together).

    >
    > No <URL:http://docs.python.org/reference/datamodel.html#object.__new__>
    > <URL:http://docs.python.org/reference/datamodel.html#object.__init__>.
    >
    > --
    >  \      “Anyone who believes exponential growth can go on forever in a |
    >   `\        finite world is either a madman or an economist.†—Kenneth |
    > _o__)                                                         Boulding |
    > Ben Finney


    Sorry for my ambiguity. I exactly mean that, but thanks for the
    docs :)
     
    StarWing, Oct 18, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jimmy
    Replies:
    1
    Views:
    3,170
    Eliyahu Goldin
    Jun 14, 2005
  2. carmen
    Replies:
    4
    Views:
    30,753
    ersecchio
    Jan 12, 2010
  3. Thorsten Kampe
    Replies:
    3
    Views:
    304
    Roy Smith
    Apr 29, 2004
  4. Jabba Laci

    list to tuple and vice versa

    Jabba Laci, Oct 18, 2009, in forum: Python
    Replies:
    0
    Views:
    304
    Jabba Laci
    Oct 18, 2009
  5. Peter Otten
    Replies:
    1
    Views:
    161
    Andreas Perstinger
    Jun 18, 2013
Loading...

Share This Page