473,404 Members | 2,187 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

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:

Apr 4 '06 #1
3 6040
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
Apr 4 '06 #2
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.
Apr 4 '06 #3
In article <ma***************************************@python. org>,
"Michael Yanowitz" <m.********@kearfott.com> 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>
Apr 5 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jinming Xu | last post by:
Hi Folks, I have a number sequence, which is put into a tuple like this: y=2, 3.0, 4.5 I can manipulate the sequence as a tuple when it has more than 1 number. But when the sequence has...
37
by: Gregor Horvath | last post by:
Hi, >>>type() <type 'list'> >>>type(('1')) <type 'str'> I wonder why ('1') is no tuple????
2
by: scott.ballard | last post by:
Greetings, I would like to know if it is possible in an XML Schema to specify an element that contains comma-delimted integers? For example, <element>1,2,3,4,5,6,7,8,9</element> Now I know...
177
by: C# Learner | last post by:
Why is C syntax so uneasy on the eye? In its day, was it _really_ designed by snobby programmers to scare away potential "n00bs"? If so, and after 50+ years of programming research, why are...
2
by: tactics40 | last post by:
I keep accidently trying to declare t-tuples as mytuple = (myitem) I know this doesn't work and that you need the trailing comma, but reading something online, I just came to realize.... the...
6
by: jeremito | last post by:
I have the following in my code a = (1,2,3) print "a = %s" %a But when I run this, I get: TypeError: not all arguments converted during string formatting Now I realize why this happens,...
2
by: slrj | last post by:
Can someone explain me what's going on in the code below. As per my knowledge "#define <macro name> <Macro replacement>" doesn't have a semicolon and it's terminated by a new line. But the code line...
7
by: erajim | last post by:
Help! I am trying to do an If statement but keep getting a "syntax error (comma)" when I try to run it. Expr1: If(<21000000,"5 – 20M",If( Between 20999999 And 51000000,"21 – 50M",If( Between...
4
by: wxPythoner | last post by:
To create a tuple with one element, you need to do this: <type 'tuple'> But if you do this <type 'int'> you don't get a tuple. I thought that just putting a value inside ( )
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.