[issue42669] "except" documentation still suggests nested tuples are allowed

2020-12-20 Thread Eric V. Smith


Change by Eric V. Smith :


--
resolution:  -> fixed
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42669] "except" documentation still suggests nested tuples are allowed

2020-12-20 Thread Eric V. Smith


Eric V. Smith  added the comment:


New changeset 81f706d2db0f57c4fdd747df6e0a4cffcbc54704 by Miss Islington (bot) 
in branch '3.8':
bpo-42669: Document that `except` rejects nested tuples (GH-23822) (GH-23871)
https://github.com/python/cpython/commit/81f706d2db0f57c4fdd747df6e0a4cffcbc54704


--

___
Python tracker 
<https://bugs.python.org/issue42669>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42669] "except" documentation still suggests nested tuples are allowed

2020-12-20 Thread Eric V. Smith


Eric V. Smith  added the comment:


New changeset 409ce4a09e4f96ca9b251c19f5819205aae9ae34 by Miss Islington (bot) 
in branch '3.9':
bpo-42669: Document that `except` rejects nested tuples (GH-23822) (GH-23870)
https://github.com/python/cpython/commit/409ce4a09e4f96ca9b251c19f5819205aae9ae34


--
nosy: +eric.smith

___
Python tracker 
<https://bugs.python.org/issue42669>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42669] "except" documentation still suggests nested tuples are allowed

2020-12-20 Thread miss-islington


Change by miss-islington :


--
pull_requests: +22733
pull_request: https://github.com/python/cpython/pull/23871

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42669] "except" documentation still suggests nested tuples are allowed

2020-12-20 Thread miss-islington


Change by miss-islington :


--
pull_requests: +22732
pull_request: https://github.com/python/cpython/pull/23870

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42669] "except" documentation still suggests nested tuples are allowed

2020-12-20 Thread miss-islington


miss-islington  added the comment:


New changeset c95f8bc2700b42f4568886505a819816c9b0ba28 by Colin Watson in 
branch 'master':
bpo-42669: Document that `except` rejects nested tuples (GH-23822)
https://github.com/python/cpython/commit/c95f8bc2700b42f4568886505a819816c9b0ba28


--
nosy: +miss-islington

___
Python tracker 
<https://bugs.python.org/issue42669>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42669] "except" documentation still suggests nested tuples are allowed

2020-12-17 Thread Colin Watson


Change by Colin Watson :


--
keywords: +patch
pull_requests: +22682
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/23822

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42669] "except" documentation still suggests nested tuples are allowed

2020-12-17 Thread Colin Watson

New submission from Colin Watson :

In Python 2, it was possible to use `except` with a nested tuple, and 
occasionally natural.  For example, `zope.formlib.interfaces.InputErrors` is a 
tuple of several exception classes, and one might reasonably think to do 
something like this (this is real code used in several places in 
https://git.launchpad.net/launchpad):

try:
self.getInputValue()
return True
except (InputErrors, SomethingElse):
return False

As of Python 3.0, this raises "TypeError: catching classes that do not inherit 
from BaseException is not allowed" instead: one must instead either break it up 
into multiple "except" clauses or flatten the tuple.  The change was mentioned 
in https://bugs.python.org/issue2380 and seems to have been intentional: I'm 
not requesting that the previous behaviour be restored, since it's a fairly 
rare porting issue and by now well-established in Python 3.

However, the relevant sentences of documentation in 
https://docs.python.org/2/reference/compound_stmts.html#try and 
https://docs.python.org/3/reference/compound_stmts.html#the-try-statement are 
identical aside from punctuation, and they both read:

 For an except clause with an expression, that expression is evaluated, and 
the clause matches the exception if the resulting object is “compatible” with 
the exception.  An object is compatible with an exception if it is the class or 
a base class of the exception object or a tuple containing an item compatible 
with the exception.

I think this admits a recursive reading: I certainly read it that way.  It 
should make it clear that nested tuples are not allowed.

--
assignee: docs@python
components: Documentation
messages: 383243
nosy: cjwatson, docs@python
priority: normal
severity: normal
status: open
title: "except" documentation still suggests nested tuples are allowed
versions: Python 3.10

___
Python tracker 
<https://bugs.python.org/issue42669>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2020-05-04 Thread Zachary Ware


Zachary Ware  added the comment:

With 2.7 out of support, closing.

--
nosy: +zach.ware
resolution:  -> out of date
stage: needs patch -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2016-09-10 Thread Alexander Belopolsky

Changes by Alexander Belopolsky :


--
assignee: belopolsky -> 
versions:  -Python 2.6, Python 2.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16253] Docs for PyArg_ParseTupleAndKeywords say it doesn't accept nested tuples

2013-10-13 Thread Georg Brandl

Georg Brandl added the comment:

This sentence appears to be from the 1.5.2 docs; I can't find it anywhere else.

--
nosy: +georg.brandl
resolution:  - invalid
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16253
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16253] Docs for PyArg_ParseTupleAndKeywords say it doesn't accept nested tuples

2012-10-16 Thread Roger Upole

New submission from Roger Upole:

The docs for this function state
Nested tuples cannot be parsed when using keyword arguments!
but this restriction was removed some time ago.

--
assignee: docs@python
components: Documentation
messages: 173081
nosy: docs@python, rupole
priority: normal
severity: normal
status: open
title: Docs for PyArg_ParseTupleAndKeywords say it doesn't accept nested tuples

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16253
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2012-08-23 Thread moijes12

Changes by moijes12 moije...@gmail.com:


--
nosy: +moijes12

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2380
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2012-08-23 Thread moijes12

Changes by moijes12 moije...@gmail.com:


--
nosy:  -moijes12

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2380
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10638] PyArg_ParseTuple: refcount in nested tuples

2010-12-06 Thread Armin Rigo

New submission from Armin Rigo ar...@users.sourceforge.net:

There is an issue in PyArg_ParseTuple() when using nested tuple arguments: it 
accepts a pure Python tuple-like argument, but it cannot work properly because 
PyArg_ParseTuple() is supposed to return borrowed references to the objects.  
For example, here is an attack on functools.partial().__setstate__(), which is 
written using

PyArg_ParseTuple(args, (), ...)

Running crasher.py crashes a debug build of Python, for me with Fatal Python 
error: _functoolsmodule.c:158 object at 0x9011748 has negative ref count 
-606348322.

The only way I can see to fix the crasher is to restrict the kind of argument 
that can be passed to mean a nested tuple.  To be paranoid, it should only 
allow real tuples; a bit more flexibly, lists probably work ok too.

--
components: Interpreter Core
files: crasher.py
messages: 123466
nosy: arigo
priority: normal
severity: normal
status: open
title: PyArg_ParseTuple: refcount in nested tuples
Added file: http://bugs.python.org/file19953/crasher.py

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10638
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10638] PyArg_ParseTuple: refcount in nested tuples

2010-12-06 Thread Georg Brandl

Georg Brandl ge...@python.org added the comment:

Duplicate of #6083?

--
nosy: +georg.brandl

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10638
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue10638] PyArg_ParseTuple: refcount in nested tuples

2010-12-06 Thread Armin Rigo

Armin Rigo ar...@users.sourceforge.net added the comment:

Indeed.

--
resolution:  - duplicate
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue10638
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2010-12-03 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Not all incompatibilities have to raise a py3k warnings; AFAIK, only those 
which are not handled by 2to3 do.

--
nosy: +benjamin.peterson, pitrou

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2380
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2010-12-01 Thread Alexander Belopolsky

Alexander Belopolsky belopol...@users.sourceforge.net added the comment:

issue2380.diff does not apply anymore.

--
assignee:  - belopolsky
stage:  - needs patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2380
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2010-06-26 Thread Ezio Melotti

Changes by Ezio Melotti ezio.melo...@gmail.com:


--
nosy: +ezio.melotti

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2380
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2010-04-28 Thread Terry J. Reedy

Changes by Terry J. Reedy tjre...@udel.edu:


--
versions: +Python 2.7

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue2380
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



Re: Accessing items in nested tuples

2009-04-22 Thread Rhodri James

On Tue, 21 Apr 2009 21:45:21 +0100, alex ale...@bluewin.ch 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', 'dd')).  You can treat that tuple in exactly
the same way as any other tuple, it just happens to have the
name data[0].  If you want to get its first element, you
stick [0] after the name, just like indexing any other tuple,
making it data[0][0].

This generalises.  You can use whatever object data[0] gives
you exactly like any other use of that type of object.  If it
gives you a dictionary, you can write:

  data[0]['spam'] = moist and delicious

and so on.

--
Rhodri James *-* Wildebeeste Herder to the Masses
--
http://mail.python.org/mailman/listinfo/python-list


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, kk, ll)))

def Process(self):
for eachData in self.Data():
print Printing %s % eachData


def main():
print Start processing data
prtData=Test()
prtData.Process()
print Stop processing data


if __name__ == '__main__':
main()


However I do not find out how to access data items in a nested tuple
of
the type ((aa, (bb, cc, dd)), (ee, (ff, gg, hh)),...).
In fact I am trying to refactor a simple GUI basing on an example
in wxPython In Action, Listing 5.5 A refactored example where the
menues
are described in the way


def menuData(self):
return ((File,
(Open, Open in status bar, self.OnOpen),
(Quit, Quit, self.OnCloseWindow)),
(Edit,
(Copy, Copy, self.OnCopy),
(Cut, Cut, self.OnCut),
 ...)))

etc...


But I can not get the example running and I can't reprogram the
example to get it running for my case.

In IDLE I can print the individual tuples but not the items within.

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.
For sure I am most probably missing something which is evident, maybe
can anybody help?
Thanks Alex

--
http://mail.python.org/mailman/listinfo/python-list


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 so close:

   print data[0][0]
  'aa'
   print data[1][0]
  'ee'

-tkc


--
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 ale...@bluewin.ch 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, dd)), (ee, (ff, gg,
 hh)), (ii, (jj, kk, ll)))

     def Process(self):
         for eachData in self.Data():
             print Printing %s % eachData

 def main():
     print Start processing data
     prtData=Test()
     prtData.Process()
     print Stop processing data

 if __name__ == '__main__':
     main()

 However I do not find out how to access data items in a nested tuple
 of
 the type ((aa, (bb, cc, dd)), (ee, (ff, gg, hh)),...).
 In fact I am trying to refactor a simple GUI basing on an example
 in wxPython In Action, Listing 5.5 A refactored example where the
 menues
 are described in the way

     def menuData(self):
         return ((File,
                 (Open, Open in status bar, self.OnOpen),
                 (Quit, Quit, self.OnCloseWindow)),
                 (Edit,
                 (Copy, Copy, self.OnCopy),
                 (Cut, Cut, self.OnCut),
                  ...)))

     etc...

 But I can not get the example running and I can't reprogram the
 example to get it running for my case.

 In IDLE I can print the individual tuples but not the items within.

 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.
 For sure I am most probably missing something which is evident, maybe
 can anybody help?

 for i in data:
print i[0],
for j in i[1]:
print j,


aa bb cc dd ee ff gg hh ii jj kk ll

 print data[0]
('aa', ('bb', 'cc', 'dd'))
 print data[0][0]
aa
 print data[0][1][0]
bb
 print data[0][1][1]
cc



 Thanks Alex

--
http://mail.python.org/mailman/listinfo/python-list


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


[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2008-05-10 Thread Bruno Gola

Bruno Gola [EMAIL PROTECTED] added the comment:

Should nested tuples in an except clause be a valid syntax?
like:
...
except ((ValueError, Exception), TypeError, (...)):
pass

I don't see any benefit and because of this behavior the implementation
(in Python/errors.c and in the patch attached) will use recursive function. 

I think that any objects inside a tuple in an except clause should be
treated equally (as an object), even a tuple, so the except clause above
should be an error in py3k and should produce a warning because the list
objects does not inherits BaseException.

Please, see my comment in http://bugs.python.org/issue2345, it is
related to this issue.

--
nosy: +brunogola

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2380
__
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2008-03-17 Thread Alexander Belopolsky

New submission from Alexander Belopolsky [EMAIL PROTECTED]:

As of r61478, the following code fails to produce a py3k warning:

try:
   raise ValueError
except ((ValueError,object),):
   pass


which is an error for in py3k:

Traceback (most recent call last):
  File x.py, line 3, in module
except ((ValueError,object),):
TypeError: catching classes that do not inherit from BaseException is 
not allowed

--
components: Interpreter Core
messages: 63875
nosy: belopolsky
severity: normal
status: open
title: Raise a Py3K warning for catching nested tuples with non-BaseException 
exceptions
type: behavior
versions: Python 2.6

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2380
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2008-03-17 Thread Guido van Rossum

Changes by Guido van Rossum [EMAIL PROTECTED]:


--
keywords: +26backport, easy
priority:  - low

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2380
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue2380] Raise a Py3K warning for catching nested tuples with non-BaseException exceptions

2008-03-17 Thread Alexander Belopolsky

Changes by Alexander Belopolsky [EMAIL PROTECTED]:


--
keywords: +patch
Added file: http://bugs.python.org/file9720/issue2380.diff

__
Tracker [EMAIL PROTECTED]
http://bugs.python.org/issue2380
__
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



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


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: 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 either

t[1]

or

t.__getitem__(1)

You're asking for the sub-element of that thing just returned. 
Thus, you either need to use

t[1][1]

or

t[1]._getitem(1)

or

t.__getitem__(1)[1]

or

t.__getitem__(1).__getitem__(1)



Imagine that you used

x = t[1]

You wouldn't use

x.[1]

you'd use

x[1]

or

x.__getitem__(1)

Same thing.  As simple as search-and-replace of t[1] with x

-tkc




-- 
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]

   File ipython console, line 1
 k.[1]
   ^
SyntaxError: invalid syntax

Note that:
In [7]: type(t[1])
Out[7]: type 'tuple'
just as t.

hth,
jss
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: nested tuples

2005-09-10 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))

I haven't found the way to do it just using tuples.  How can I do it?

Nevertheless, I can solve it like this:
a=[]

for row in reader:
~   elem = (row[0],row[1],row[2])
~   a.append(elem)

which will result in a list of tuples: [(row1value1, row1value2,
row1value3),(row2value1, row2value2, row2value3),..., (rowNvalue1,
rowNvalue2, rowNvalue3)]

Then, I get what I want with tuple(a).

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.
-- 
- Tim Roberts, [EMAIL PROTECTED]
  Providenza  Boekelheide, Inc.
-- 
http://mail.python.org/mailman/listinfo/python-list


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 exclusively tuples.

Regards,

Luis Mendes
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDIqgSHn4UHCY8rB8RAps/AJ905JXc5naxJYWLA0JLd0ZaJfQQWACeLXHJ
pLE9nmMH+k81ybbB1Otj0hg=
=2/LC
-END PGP SIGNATURE-
-- 
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 there
 was a way to do it using exclusively tuples.

A list of lists can be built top down.  A tuple of tuples must be built 
bottom up, and each tuple must be built with one call to tuple().  But 
tuple(it) will take any iterable, so write, say, a generator that yields 
lower-level tuples.

Terry J. Reedy



-- 
http://mail.python.org/mailman/listinfo/python-list


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))

I haven't found the way to do it just using tuples.  How can I do it?

Nevertheless, I can solve it like this:
a=[]

for row in reader:
~   elem = (row[0],row[1],row[2])
~   a.append(elem)

which will result in a list of tuples: [(row1value1, row1value2,
row1value3),(row2value1, row2value2, row2value3),..., (rowNvalue1,
rowNvalue2, rowNvalue3)]

Then, I get what I want with tuple(a).



Luis P. Mendes
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDIdcvHn4UHCY8rB8RAjBnAJ9hLzbMZVZf3vLZ0iCs2ptK0v6RPwCfRr1S
GHdoy/APTZSWy+rLBA+i0KE=
=vyR6
-END PGP SIGNATURE-
-- 
http://mail.python.org/mailman/listinfo/python-list


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 do it just using tuples.  How can I do
 it? 
 
 Nevertheless, I can solve it like this:
 a=[]
 
 for row in reader:
 ~   elem = (row[0],row[1],row[2])
 ~   a.append(elem)
 
 which will result in a list of tuples: [(row1value1, row1value2,
 row1value3),(row2value1, row2value2, row2value3),...,
 (rowNvalue1, rowNvalue2, rowNvalue3)]

tuple() will consume a list.

 tuple([1,2,3])
(1, 2, 3)
 tuple([(1,2),(3,4),(5,6)])
((1, 2), (3, 4), (5, 6))


max
-- 
http://mail.python.org/mailman/listinfo/python-list


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 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 do it just using tuples.  How can I do it?
 
 Nevertheless, I can solve it like this:
 a=[]
 
 for row in reader:
 ~   elem = (row[0],row[1],row[2])
 ~   a.append(elem)
 
 which will result in a list of tuples: [(row1value1, row1value2,
 row1value3),(row2value1, row2value2, row2value3),..., (rowNvalue1,
 rowNvalue2, rowNvalue3)]
 
 Then, I get what I want with tuple(a).
 
 
 
 Luis P. Mendes
-- 
http://mail.python.org/mailman/listinfo/python-list