On Fri, Dec 04, 2009 at 15:17 +0300, Петров Александр wrote: > 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 ?
The following might clarify the issue: >>> t = (1) >>> type(t) <type 'int'> >>> t = (1,) >>> type(t) <type 'tuple'> >>> t = 1, >>> type(t) <type 'tuple'> It is the ',' not the '(' and ')' ... -- .''`. Wolodja Wentland <wentl...@cl.uni-heidelberg.de> : :' : `. `'` 4096R/CAF14EFC `- 081C B7CD FF04 2BA9 94EA 36B2 8B7F 7D30 CAF1 4EFC
signature.asc
Description: Digital signature
-- http://mail.python.org/mailman/listinfo/python-list