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

Петров Александр gmdidro at gmail.com
Fri Dec 4 07:17:27 EST 2009


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



More information about the Python-list mailing list