Re: maybe a bug in python
If you have any doubts, try to remeber this when creating tuples, if a tuple is to have 0 elements, then it must be given as a=() in other words, the ( and the ) are essential if it has one element, then a comma after that element is essential a=1, or alternatively a=(1,) in other words, an end comma is essential but the parentheses are not if it has more than one element, comma between the elements is only essential a=1,2 or alternatively a=1,2, or alternatively a=(1,2) i might have made some silly mistake so wait till some one points it out (if the mistakes are there) :) flyaflya wrote: a = {1: (a)} a[1] '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 -- http://mail.python.org/mailman/listinfo/python-list
Re: maybe a bug in python
venkata subramanian wrote: If you have any doubts, try to remeber this when creating tuples, if a tuple is to have 0 elements, then it must be given as a=() in other words, the ( and the ) are essential if it has one element, then a comma after that element is essential a=1, or alternatively a=(1,) in other words, an end comma is essential but the parentheses are not if it has more than one element, comma between the elements is only essential a=1,2 or alternatively a=1,2, or alternatively a=(1,2) That actually looks like a pretty good summary. I've posted it, with a few elaborations at: http://wiki.python.org/moin/TupleSyntax STeVe -- http://mail.python.org/mailman/listinfo/python-list
maybe a bug in python
a = {1: (a)} a[1] '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. -- [http://www.flyaflya.com/] -- http://mail.python.org/mailman/listinfo/python-list
Re: maybe a bug in python
flyaflya wrote: a = {1: (a)} a[1] '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. (a) is just a simple expression. You need to add a comma so that Python knows you want a tuple. Thusly... (a,) Will McGugan -- http://www.willmcgugan.com .join({'*':'@','^':'.'}.get(c,0) or chr(97+(ord(c)-84)%26) for c in jvyy*jvyyzpthtna^pbz) -- http://mail.python.org/mailman/listinfo/python-list
Re: maybe a bug in python
Hallchen! flyaflya [EMAIL PROTECTED] writes: a = {1: (a)} a[1] 'a' why not ('a')? (a) is not a tuple, but (a,) is. Tsch, Torsten. -- Torsten Bronger, aquisgrana, europa vetus -- http://mail.python.org/mailman/listinfo/python-list
Re: maybe a bug in python
flyaflya wrote: a = {1: (a)} a[1] '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 -- http://mail.python.org/mailman/listinfo/python-list
Re: maybe a bug in python
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#SECTION00730 my 2 cents Regards, Tiago S Daitx On 6/5/05, flyaflya [EMAIL PROTECTED] wrote: a = {1: (a)} a[1]'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.--[http://www.flyaflya.com/]-- http://mail.python.org/mailman/listinfo/python-list -- http://mail.python.org/mailman/listinfo/python-list
Re: maybe a bug in python: NOW Pythonic Gotchas
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 Tiago Stürmer Daitx wrote: 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#SECTION00730 my 2 cents Regards, Tiago S Daitx On 6/5/05, flyaflya [EMAIL PROTECTED] wrote: a = {1: (a)} a[1] '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. -- [http://www.flyaflya.com/] -- http://mail.python.org/mailman/listinfo/python-list --- -- http://mail.python.org/mailman/listinfo/python-list -- -- 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 -- http://mail.python.org/mailman/listinfo/python-list