Re: tuple syntax ',' (ending in comma?)
In article [EMAIL PROTECTED], Michael Yanowitz [EMAIL PROTECTED] wrote: I am confused by the syntax for tuples. ... The way I fixed this error was I added an extra , (comma) to the tuple: thread.start_new_thread(read_data_thread, (strDataFilename,)) 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. http://python.org/doc/2.4.2/ref/parenthesized.html -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple syntax ',' (ending in comma?)
On Wed, 05 Apr 2006 08:17:07 +1000, Ben Finney wrote: Michael Yanowitz [EMAIL PROTECTED] 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. With the introduction of generator expressions, I'm sure the next generation of newcomers will have a brand new source of confusion whenever they see a pair of parentheses, ensuring plenty of work for those writing tutorials and books. And they say that language designers don't think of the future. *wink* -- Steven. -- http://mail.python.org/mailman/listinfo/python-list
tuple syntax ',' (ending in comma?)
Hello: I am still relatively new to Python. I am confused by the syntax for tuples. I had: thread.start_new_thread(read_data_thread, (strDataFilename)) and got back the following error: File scene.py, line 256, in readData thread.start_new_thread(read_data_thread, (strDataFilename)) TypeError: 2nd arg must be a tuple The way I fixed this error was I added an extra , (comma) to the tuple: thread.start_new_thread(read_data_thread, (strDataFilename,)) 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. Thanks in advance: -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple syntax ',' (ending in comma?)
Michael Yanowitz wrote: Hello: I am still relatively new to Python. I am confused by the syntax for tuples. I had: thread.start_new_thread(read_data_thread, (strDataFilename)) and got back the following error: File scene.py, line 256, in readData thread.start_new_thread(read_data_thread, (strDataFilename)) TypeError: 2nd arg must be a tuple The way I fixed this error was I added an extra , (comma) to the tuple: thread.start_new_thread(read_data_thread, (strDataFilename,)) 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. What would you expect 3 * (5 + 2) to print? Certainly not (7, 7, 7), but it would if all expressions in parentheses were tuples. Thus, the comma is necessary to disambiguate and explicitly tell the parser that you mean to construct a tuple. Georg -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple syntax ',' (ending in comma?)
Michael Yanowitz wrote: 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. But isn't it incorrect to think in terms of 'parameters' when referring to tuples? Tuples just contain elements, not parameters, so it might help not to think of it as function call syntax. -- http://mail.python.org/mailman/listinfo/python-list
Re: tuple syntax ',' (ending in comma?)
Michael Yanowitz [EMAIL PROTECTED] 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 -- http://mail.python.org/mailman/listinfo/python-list