maybe a bug in python

S

Steve Horsley

flyaflya said:
'a'
why not ('a')? when
a = {1: ((("a")))}
a[1]
'a'
the result is 'a' too,not ((("a"))).but when use["a"] or ("a","b"),the
tuple is longer than 1, it's no problem.

To define a tuple literal with one member, you must place a comma
after the first element like this:

a = {1: ("a",)}

I read this somewhere in the python docs, so I know its there
somewhere.

The comma eliminates ambiguity as to the meaning of the brackets,
which without the comma are simply enclosing and precedence
controlling brackets.

Steve
 
I

Ivan Van Laningham

Hi All--
This little gotcha ought to be number one on "The Official List of
Pythonic Gotchas," which should be required reading for everyone.

What? There isn't one? Why not?

Send me your tired, your poor, your huddled gotchas yearning to breathe
free. I'll whup 'em into shape and make a doc page. The gods of
documentation (as opposed to the gods _in_ documentation) can transfer
it to the Official Documentation Homeland, or not, as they see fit.

Metta,
Ivan
Just as everyone said, use ('a',) instead of ('a'). As Steve said
there are lots of documentation about it. Check the Library Reference
at http://www.python.org/doc/current/lib/typesseq.html#l2h-155 or to
make things more clear you could read the tuples section in the
tutorial at
http://docs.python.org/tut/node7.html#SECTION007300000000000000000

my 2 cents

Regards,
Tiago S Daitx

'a'
why not ('a')? when
a = {1: ((("a")))}
a[1]
'a'
the result is 'a' too,not ((("a"))).but when use["a"] or
("a","b"),the
tuple is longer than 1, it's no problem.

--
----------------------------------------------
Ivan Van Laningham
God N Locomotive Works
http://www.pauahtun.org/
http://www.foretec.com/python/workshops/1998-11/proceedings.html
Army Signal Corps: Cu Chi, Class of '70
Author: Teach Yourself Python in 24 Hours
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,241
Messages
2,571,219
Members
47,850
Latest member
StewartTha

Latest Threads

Top