tuple syntax ',' (ending in comma?)

Ben Finney bignose+hates-spam at benfinney.id.au
Tue Apr 4 18:17:07 EDT 2006


"Michael Yanowitz" <m.yanowitz at kearfott.com> writes:

>    I am still relatively new to Python. I am confused by the syntax
> for tuples.

Well, it's reassuring to know that this is still as confusing for
newcomers now as it was when I started.

>   File "scene.py", line 256, in readData
>     thread.start_new_thread(read_data_thread, (strDataFilename))
> TypeError: 2nd arg must be a tuple

Yes, parentheses are not sufficient (and often are unnecessary) to
make a tuple. The important syntax for a tuple is the comma.

    <URL:http://docs.python.org/lib/typesseq.html>

> The way I fixed this error was I added an extra , (comma) to the
> tuple:

>   thread.start_new_thread(read_data_thread, (strDataFilename,))

That's the correct way to do it, yes.

>   I am just confused by the syntax. I am used to a comma meaning
> that there should be another parameter after the comma and if no
> additional parameter the comma would not be necessary.

This is a known wart, one that many people would like to see fixed.

For more discussion (which will likely be repeated in this thread),
see this thread from around this time last year:

    <URL:http://mail.python.org/pipermail/python-list/2005-March/271180.html>

-- 
 \          "Speech is conveniently located midway between thought and |
  `\     action, where it often substitutes for both."  -- John Andrew |
_o__)                                  Holmes, _Wisdom in Small Doses_ |
Ben Finney




More information about the Python-list mailing list