Re: Accessing items in nested tuples

2009-04-22 Thread Rhodri James
On Tue, 21 Apr 2009 21:45:21 +0100, alex wrote: Tim and Mensanator Thank you very much, this will get me further. I can not recall having seen this in my books... I am still getting my grips with Python and OOP. Think of it this way, Alex: data[0] gave you back the tuple ('aa', ('bb', 'cc',

Re: Accessing items in nested tuples

2009-04-21 Thread alex
Tim and Mensanator Thank you very much, this will get me further. I can not recall having seen this in my books... I am still getting my grips with Python and OOP. Regards Alex -- http://mail.python.org/mailman/listinfo/python-list

Re: Accessing items in nested tuples

2009-04-21 Thread Mensanator
On Apr 21, 3:03 pm, alex wrote: > Hello everybody > I am able to access the data in a tuple via a for loop (see example > below). > > #!/usr/bin/env python > > class Test(): >     def Data(self): >         return ("aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh") > #        return (("aa", ("bb", "cc

Re: Accessing items in nested tuples

2009-04-21 Thread Tim Chase
IDLE 1.2.1 data=(("aa", ("bb", "cc", "dd")), ("ee", ("ff", "gg", "hh")), ("ii", ("jj", "kk", "ll"))) print data[0] ('aa', ('bb', 'cc', 'dd')) print data[1] ('ee', ('ff', 'gg', 'hh')) etc... I would like to be able to access the dataitem "aa" or "bb", "cc", "dd" individualy. You're s

Accessing items in nested tuples

2009-04-21 Thread alex
Hello everybody I am able to access the data in a tuple via a for loop (see example below). #!/usr/bin/env python class Test(): def Data(self): return ("aa", "bb", "cc", "dd", "ee", "ff", "gg", "hh") #return (("aa", ("bb", "cc", "dd")), ("ee", ("ff", "gg", "hh")), ("ii", ("jj

Re: Access elements from nested tuples

2006-09-05 Thread Georg Sauthoff
On 2006-09-04, Tim Chase <[EMAIL PROTECTED]> wrote: Hi, [nested tuples] thanks - I should not post before 8 am or 10 pm ... Regards Georg Sauthoff -- http://mail.python.org/mailman/listinfo/python-list

Re: Access elements from nested tuples

2006-09-04 Thread jss
Hi Georg! In [1]: t=(1,(2,3)) > I am bit suprised, that I cannot access '3' via: > t[1].[1] # syntax error > > But t[1].__getitem__(1) works like expected. In [2]: k=t[1] In [3]: k[1] Out[3]: 3 In [4]: t[1][1] Out[4]: 3 In [5]: k.__getitem__(1) Out[5]: 3 In [6]: k.[1] ---

Re: Access elements from nested tuples

2006-09-04 Thread Tim Chase
> t = (1, (2, 3)) > > I am bit suprised, that I cannot access '3' via: > t[1].[1] # syntax error > > But t[1].__getitem__(1) works like expected. > > Why is that? What is "t"? It's a tuple. A tuple can be indexed, or you can call its __getitem__ method. Thus, the one-th element of t is eith

Access elements from nested tuples

2006-09-04 Thread Georg Sauthoff
Hi, t = (1, (2, 3)) I am bit suprised, that I cannot access '3' via: t[1].[1] # syntax error But t[1].__getitem__(1) works like expected. Why is that? Regards Georg Sauthoff -- http://mail.python.org/mailman/listinfo/python-list

Re: nested tuples

2005-09-10 Thread Terry Reedy
"Luis P. Mendes" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > | Why? What is it about the list of tuples that you don't like? > | Philosophically, it's more in line with Guido's separation of list and > | tuple. > I'm not saying that I don't like, I was just curious to know if t

Re: nested tuples

2005-09-10 Thread Luis P. Mendes
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 | | Why? What is it about the list of tuples that you don't like? | Philosophically, it's more in line with Guido's separation of list and | tuple. I'm not saying that I don't like, I was just curious to know if there was a way to do it using exclusi

Re: nested tuples

2005-09-09 Thread Tim Roberts
"Luis P. Mendes" <[EMAIL PROTECTED]> wrote: > >I'm trying to solve this problem: > >suppose I'm reading a csv file and want to create a tuple of all those >rows and values, like ((row1value1, row1value2, row1value3),(row2value1, >row2value2, row2value3),..., (rowNvalue1, rowNvalue2, rowNvalue3)) >

Re: nested tuples

2005-09-09 Thread Larry Bates
The first question is why do you need tuples? But this works: import csv filename=r'C:\test.txt' fp=open(filename,'r') reader=csv.reader(fp) tlines=tuple([tuple(x) for x in reader]) fp.close() Larry Bates Luis P. Mendes wrote: > Hi, > > I'm trying to solve this problem: > > suppose I'm readin

Re: nested tuples

2005-09-09 Thread Max Erickson
"Luis P. Mendes" <[EMAIL PROTECTED]> wrote in > suppose I'm reading a csv file and want to create a tuple of all > those rows and values, like ((row1value1, row1value2, > row1value3),(row2value1, row2value2, row2value3),..., > (rowNvalue1, rowNvalue2, rowNvalue3)) > > I haven't found the way to d

nested tuples

2005-09-09 Thread Luis P. Mendes
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Hi, I'm trying to solve this problem: suppose I'm reading a csv file and want to create a tuple of all those rows and values, like ((row1value1, row1value2, row1value3),(row2value1, row2value2, row2value3),..., (rowNvalue1, rowNvalue2, rowNvalue3))