Why the expression "(1)" is not an one-arity tuple, but int ?

Discussion in 'Python' started by ðÅÔÒÏ× áÌÅËÓÁÎÄÒ, Dec 4, 2009.

  1. Hello All !

    In my code I try to use a generic approach to work with tuples. Let
    "X" be a tuple.
    When I want to access a first element of a tuple, I can write: "X[0]".
    And that is really working when X is a n-arity tuple, with n>1 (for
    example "foo( (1,2,3) )" ).
    But when I call my library function with a 1-arity tuple (for example
    "foo( (1) )" ) I have an error:

    TypeError: 'int' object is unsubscriptable

    How could I tell Python that "(1)" is not an integer, but an one-arity tuple ?

    Thank you,
    Alexander Petrov
     
    ðÅÔÒÏ× áÌÅËÓÁÎÄÒ, Dec 4, 2009
    #1
    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. Schnoffos
    Replies:
    2
    Views:
    1,252
    Martien Verbruggen
    Jun 27, 2003
  2. Gregor Horvath

    Why tuple with one item is no tuple

    Gregor Horvath, Mar 15, 2005, in forum: Python
    Replies:
    37
    Views:
    868
    Antoon Pardon
    Mar 30, 2005
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,239
    Smokey Grindel
    Dec 2, 2006
  4. aling
    Replies:
    8
    Views:
    1,036
    Jim Langston
    Oct 20, 2005
  5. Replies:
    9
    Views:
    465
    James Kanze
    Apr 17, 2007
Loading...

Share This Page