Re: [Python-Dev] pprint(iterator)

2009-02-02 Thread Robert Kern
On 2009-02-02 14:50, Nick Coghlan wrote: Really drastic performance degradations would be on the radar as well - slowing pprint() down by 10% is unlikely to bother anyone, but slowing it down by 100% would be a bad thing (not that I think such a degradation is likely, I'm just trying to give an i

Re: [Python-Dev] pprint(iterator)

2009-02-02 Thread Nick Coghlan
Tres Seaver wrote: > Nick Coghlan wrote: >> (and don't worry too much about 3 - it will give me an opportunity to >> road test the functools patch by using it to refactor pprint and check >> the performance implications) > > /me wonders about the performance-criticality of anything using > 'pprint

Re: [Python-Dev] pprint(iterator)

2009-02-02 Thread Matthew Wilkes
On 29 Jan 2009, at 21:54, Nick Coghlan wrote: For the "reiterable" cases like dictionary views (where the object is not consumed), an appropriate __str__ or __repr__ should be written). Indeed, instead of having a __pprint__ why not just allow a __repr__ to reformat its output? dict havin

Re: [Python-Dev] pprint(iterator)

2009-02-02 Thread Paul Moore
2009/2/2 Nick Coghlan : > Paul Moore wrote: >> 2009/2/2 Nick Coghlan : >>> A trio of patches that: >>> 1. promoted simplegeneric from pkgutil to functools (with appropriate >>> documentation and tests) >>> 2. changed pkgutil to use functools.simplegeneric instead of its current >>> internal versio

Re: [Python-Dev] pprint(iterator)

2009-02-02 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Nick Coghlan wrote: > Paul Moore wrote: >> 2009/2/2 Nick Coghlan : >>> A trio of patches that: >>> 1. promoted simplegeneric from pkgutil to functools (with appropriate >>> documentation and tests) >>> 2. changed pkgutil to use functools.simplegeneric

Re: [Python-Dev] pprint(iterator)

2009-02-02 Thread Nick Coghlan
Paul Moore wrote: > 2009/2/2 Nick Coghlan : >> A trio of patches that: >> 1. promoted simplegeneric from pkgutil to functools (with appropriate >> documentation and tests) >> 2. changed pkgutil to use functools.simplegeneric instead of its current >> internal version >> 3. updated pprint to be a g

Re: [Python-Dev] pprint(iterator)

2009-02-02 Thread Paul Moore
2009/2/2 Nick Coghlan : > A trio of patches that: > 1. promoted simplegeneric from pkgutil to functools (with appropriate > documentation and tests) > 2. changed pkgutil to use functools.simplegeneric instead of its current > internal version > 3. updated pprint to be a generic function (and hence

Re: [Python-Dev] pprint(iterator)

2009-02-02 Thread Nick Coghlan
Walter Dörwald wrote: > Paul Moore wrote: >> 2009/1/30 Walter Dörwald : >>> Paul Moore wrote: >>> [...] In all honesty, I think pkgutil.simplegeneric should be documented, exposed, and moved to a library of its own[1]. >>> http://pypi.python.org/pypi/simplegeneric >> >> Thanks, I was

Re: [Python-Dev] pprint(iterator)

2009-02-02 Thread Walter Dörwald
Paul Moore wrote: 2009/1/30 Walter Dörwald : Paul Moore wrote: [...] In all honesty, I think pkgutil.simplegeneric should be documented, exposed, and moved to a library of its own[1]. http://pypi.python.org/pypi/simplegeneric Thanks, I was aware of that. I wasn't aware of the fact that si

Re: [Python-Dev] pprint(iterator)

2009-01-30 Thread Walter Dörwald
Paul Moore wrote: > [...] > In all honesty, I think pkgutil.simplegeneric should be documented, > exposed, and moved to a library of its own[1]. http://pypi.python.org/pypi/simplegeneric > [...] Servus, Walter ___ Python-Dev mailing list Python-De

Re: [Python-Dev] pprint(iterator)

2009-01-30 Thread Paul Moore
2009/1/30 Walter Dörwald : > Paul Moore wrote: > >> [...] >> In all honesty, I think pkgutil.simplegeneric should be documented, >> exposed, and moved to a library of its own[1]. > > http://pypi.python.org/pypi/simplegeneric Thanks, I was aware of that. I assume that the barrier to getting this in

Re: [Python-Dev] pprint(iterator)

2009-01-30 Thread Eric Smith
Steven D'Aprano wrote: Eric Smith wrote: Terry Reedy wrote: Ron Adam wrote: Steven D'Aprano wrote: Michael Foord wrote: Don't we have a pretty-print API - and isn't it spelled __str__ ? Not really. If it were as simple as calling str(obj), there would be no need for the pprint module.

Re: [Python-Dev] pprint(iterator)

2009-01-30 Thread Paul Moore
2009/1/30 Steven D'Aprano : >> But that's beside the >> >> point, I don't like __pprint__ in any event. Too special. > > I'm not sure what you mean by "too special". It's no more special than any > other special method. Do you mean the use-case is not common enough? I would > find this useful. Whet

Re: [Python-Dev] pprint(iterator)

2009-01-30 Thread Steven D'Aprano
Eric Smith wrote: Terry Reedy wrote: Ron Adam wrote: Steven D'Aprano wrote: Michael Foord wrote: Don't we have a pretty-print API - and isn't it spelled __str__ ? Not really. If it were as simple as calling str(obj), there would be no need for the pprint module. I agree. And when I w

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Eric Smith
Terry Reedy wrote: Ron Adam wrote: Steven D'Aprano wrote: Michael Foord wrote: Don't we have a pretty-print API - and isn't it spelled __str__ ? Not really. If it were as simple as calling str(obj), there would be no need for the pprint module. I agree. And when I want to use pprint,

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Terry Reedy
Ron Adam wrote: Steven D'Aprano wrote: Michael Foord wrote: Don't we have a pretty-print API - and isn't it spelled __str__ ? Not really. If it were as simple as calling str(obj), there would be no need for the pprint module. I agree. And when I want to use pprint, there are usually ad

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Ron Adam
Steven D'Aprano wrote: Michael Foord wrote: Don't we have a pretty-print API - and isn't it spelled __str__ ? Not really. If it were as simple as calling str(obj), there would be no need for the pprint module. I agree. And when I want to use pprint, there are usually additional output

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Antoine Pitrou
Raymond Hettinger rcn.com> writes: > > P.S. My other experience with 3.0 is that my most frequent error has > changed. It used to be that the number reason for my getting a syntax > error was leaving-off a colon. Now, my number one reason is > omitting parens in a print() function call. I tho

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Raymond Hettinger
Along the lines of what others have said: pprint() cannot consume an unknown iterator. Perhaps so. It's nice to have printing be free of side-effects (other than the actual printing). I've been working with 3.0 daily for several months (on a book project) and mostly think it's great. But

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Robert Kern
On 2009-01-29 08:20, Aahz wrote: The reason I'm chiming in is that I would welcome a PEP that created a __pprint__ method as an alternative to special-casing. I think that it would be generically useful for user-created objects, plus once you've added this feature other people can easily do som

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Steven D'Aprano
Michael Foord wrote: Don't we have a pretty-print API - and isn't it spelled __str__ ? Not really. If it were as simple as calling str(obj), there would be no need for the pprint module. In any case, it seems that the pprint module actually calls repr() on objects other than dicts, tuples an

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Nick Coghlan
Michael Foord wrote: > Don't we have a pretty-print API - and isn't it spelled __str__ ? For the "reiterable" cases like dictionary views (where the object is not consumed), an appropriate __str__ or __repr__ should be written). Whether that is something as simple as ".items()" for an items view,

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Paul Moore
2009/1/29 Oleg Broytmann : > On Thu, Jan 29, 2009 at 08:06:18AM -0800, Aahz wrote: >> On Thu, Jan 29, 2009, Michael Foord wrote: >> > Don't we have a pretty-print API - and isn't it spelled __str__ ? >> >> In theory, yes. In practice, we wouldn't be having this discussion if >> that really worked.

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Oleg Broytmann
On Thu, Jan 29, 2009 at 08:06:18AM -0800, Aahz wrote: > On Thu, Jan 29, 2009, Michael Foord wrote: > > Don't we have a pretty-print API - and isn't it spelled __str__ ? > > In theory, yes. In practice, we wouldn't be having this discussion if > that really worked. But it probably would make sens

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Aahz
On Thu, Jan 29, 2009, Michael Foord wrote: > Aahz wrote: >> On Tue, Jan 27, 2009, Raymond Hettinger wrote: >> >>> It is becoming the norm in 3.x for functions to return iterators, >>> generators, or views whereever possible. >>> >>> I had a thought that pprint() ought to be taught to print itera

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Michael Foord
Aahz wrote: On Tue, Jan 27, 2009, Raymond Hettinger wrote: It is becoming the norm in 3.x for functions to return iterators, generators, or views whereever possible. I had a thought that pprint() ought to be taught to print iterators: pprint(enumerate(seq)) pprint(map(somefunc, someda

Re: [Python-Dev] pprint(iterator)

2009-01-29 Thread Aahz
On Tue, Jan 27, 2009, Raymond Hettinger wrote: > > It is becoming the norm in 3.x for functions to return iterators, > generators, or views whereever possible. > > I had a thought that pprint() ought to be taught to print iterators: > >pprint(enumerate(seq)) >pprint(map(somefunc, somedata))

Re: [Python-Dev] pprint(iterator)

2009-01-27 Thread Guido van Rossum
On Tue, Jan 27, 2009 at 2:24 PM, Raymond Hettinger wrote: > > [Guido van Rossum] >> >> My only thought is that whatever you do, target Python 3.1, not 3.0.1. > > Of course. > Do you have any thoughts on the most useful display format? > What do you want to see from pprint(mydict.items())? Perhaps

Re: [Python-Dev] pprint(iterator)

2009-01-27 Thread Raymond Hettinger
[Guido van Rossum] My only thought is that whatever you do, target Python 3.1, not 3.0.1. Of course. Do you have any thoughts on the most useful display format? What do you want to see from pprint(mydict.items())? Raymond ___ Python-Dev mailing

Re: [Python-Dev] pprint(iterator)

2009-01-27 Thread Guido van Rossum
On Tue, Jan 27, 2009 at 2:12 PM, Benjamin Peterson wrote: > On Tue, Jan 27, 2009 at 3:46 PM, Raymond Hettinger wrote: >> It is becoming the norm in 3.x for functions to return iterators, >> generators, or views whereever possible. > >> Do you guys have any thoughts on the subject? > > Maybe a sol

Re: [Python-Dev] pprint(iterator)

2009-01-27 Thread Nick Coghlan
Raymond Hettinger wrote: > I quite like the idea of something along those lines. For example: try: itr = iter(obj) except TypeError: pass else: return "" % (obj.__class__.__name__, )) Doing this only in pprint also reduces the chances of accidentally con

Re: [Python-Dev] pprint(iterator)

2009-01-27 Thread Guido van Rossum
On Tue, Jan 27, 2009 at 2:06 PM, Oleg Broytmann wrote: > On Tue, Jan 27, 2009 at 01:46:35PM -0800, Raymond Hettinger wrote: >> > > I like the idea, and I prefer this formatting. Also bear in mind there > are infinite generators, and there are iterators that cannot be reset. For > infinite ge

Re: [Python-Dev] pprint(iterator)

2009-01-27 Thread Benjamin Peterson
On Tue, Jan 27, 2009 at 3:46 PM, Raymond Hettinger wrote: > It is becoming the norm in 3.x for functions to return iterators, > generators, or views whereever possible. > Do you guys have any thoughts on the subject? Maybe a solution like this could help with bugs like #2610? -- Regards, Ben

Re: [Python-Dev] pprint(iterator)

2009-01-27 Thread Oleg Broytmann
On Tue, Jan 27, 2009 at 01:46:35PM -0800, Raymond Hettinger wrote: > I like the idea, and I prefer this formatting. Also bear in mind there are infinite generators, and there are iterators that cannot be reset. For infinite generators pprint() must have a parameter, say, 'max_items', and pr

Re: [Python-Dev] pprint(iterator)

2009-01-27 Thread Guido van Rossum
My only thought is that whatever you do, target Python 3.1, not 3.0.1. On Tue, Jan 27, 2009 at 1:46 PM, Raymond Hettinger wrote: > It is becoming the norm in 3.x for functions to return iterators, > generators, or views whereever possible. > > I had a thought that pprint() ought to be taught to p