473,799 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_ne w_thread(read_d ata_thread, (strDataFilenam e))
and got back the following error:

File "scene.py", line 256, in readData
thread.start_ne w_thread(read_d ata_thread, (strDataFilenam e))
TypeError: 2nd arg must be a tuple

The way I fixed this error was I added an extra , (comma) to the tuple:
thread.start_ne w_thread(read_d ata_thread, (strDataFilenam e,))

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 6066
Michael Yanowitz wrote:
Hello:

I am still relatively new to Python. I am confused by the syntax for
tuples.
I had:
thread.start_ne w_thread(read_d ata_thread, (strDataFilenam e))
and got back the following error:

File "scene.py", line 256, in readData
thread.start_ne w_thread(read_d ata_thread, (strDataFilenam e))
TypeError: 2nd arg must be a tuple

The way I fixed this error was I added an extra , (comma) to the tuple:
thread.start_ne w_thread(read_d ata_thread, (strDataFilenam e,))

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************ *************** ************@py thon.org>,
"Michael Yanowitz" <m.********@kea rfott.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_ne w_thread(read_d ata_thread, (strDataFilenam e,))

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.h tml>
Apr 5 '06 #4

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

Similar topics

10
1777
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 only 1 number, like y=2
37
2396
by: Gregor Horvath | last post by:
Hi, >>>type() <type 'list'> >>>type(('1')) <type 'str'> I wonder why ('1') is no tuple????
2
4897
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 you might say it's better to split the array into distinct elements. However, some of the elements will have so many integers that the overhead of the extra XML tags will bloat the file. So back
177
7103
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 programming languages still being designed with C's syntax? These questions drive me insane. Every waking minute...
2
1272
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 parenthesises don't have any special meaning in relation to tuples at all, do they?
6
2450
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, a is actually 3 elements when the print
2
3763
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 in bold below has a semicolon and is followed by a function declaration. (This is a piece of working, complied code) #define CST_CC_ERR LogMsg; s_ReportCSTFailure // Sets __FILE__ and __LINE__ static void s_ReportCSTFailure( const string&...
7
4168
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 50999999 And 101000000,"51 – 100M"," "))) I am using Access 2000. In case it isn't clear what I'm trying to do I would like it to return a value - If the sales amount is less than 210000000 return the value of "5 - 20M", if not less than...
4
1644
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
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9544
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10490
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10259
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9077
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5589
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.