Tuple passed to function recognised as string

Scott David Daniels Scott.Daniels at Acm.Org
Thu Mar 19 01:16:39 CET 2009


Mike314 wrote: (paraphrased)
> >>> test_func(val=('val1'))
> <type 'str'>
> >>> test_func(val=('val1', 'val2'))
> <type 'tuple'>
> The output is quite different. Why I have string in the first case?

More natural English:  "Why do I get string in the first case?"

(X) is the same as X (parentheses are for grouping), to get
a singleton, you need (X,).  ((((3)))) is just a 3 with a bunch
of meaningless parens around it.  So, you want:
     test_func(val=('val1',))

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list