Re: Sort the values of a dict

2009-12-18 Thread MRAB
Rory Campbell-Lange wrote: On 18/12/09, mattia (ger...@gmail.com) wrote: Hi all, I have a dictionary that uses dates and a tuples ad key, value pairs. I need to sort the values of the dict and insert everything in a tuple. The additional problem is that I need to sort the values looking at the

Re: Eclipse Carriage Return Workaround

2009-12-18 Thread Gregory Ewing
Steve Holden wrote: Can anyone think of a simple way work around this issue by overriding __builtins__.input() with a function that calls input() and then returns an rstrip()ped version of the input string? I though of setting a PYTHONSTARTUP environment variable, but that only affects interacti

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Alf P. Steinbach
* Mensanator: The second deviation is that since most names are constants, Really? Does that mean you don't use literals, to save the time required to convert them to integers? Isn't that done at compile time? So, instead of doing the Collatz Conjecture as while a>1: f = gmpy.scan1(a,0) i

Re: iterators and views of lists

2009-12-18 Thread Steven D'Aprano
On Fri, 18 Dec 2009 10:39:15 -0800, Carl Banks wrote: > It is true that Python iterators can't be used to mutate the underlying > structure--if there is actual underlying data structure-- An iterator is a protocol. So long as you have __iter__ and next (or __next__ in Python 3) methods, your cl

Re: ANN: withrestart 0.2.1

2009-12-18 Thread Ryan Kelly
On Fri, 2009-12-18 at 07:12 -0500, Neal Becker wrote: > I haven't tried it, but it sounds really cool. I suppose I should expect a > lot more overhead compared to try/except, since it's not built-in to python? It's a pretty thin layer on top of try/except so I'll be surprised if there is *too* m

Re: shouldn't list comprehension be faster than for loops?

2009-12-18 Thread Ryan Kelly
> > Tenting the time spent by each approach (using time.clock()), with a > > file with about 100,000 entries, I get 0.03s for the loop and 0.05s > > for the listcomp. > > Anything else being equal, list comprehensions will be the faster > becuase they incur fewer name and attribute lookups. It wil

tarfiles usage on python 2.4.4

2009-12-18 Thread tekion
All, I am using tarfile module and my python is version 2.4.4. When I call method extractall, I am getting error method does not exist. Could someone confirm if the method exist on python 2.4.4? Thanks -- http://mail.python.org/mailman/listinfo/python-list

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Steven D'Aprano
On Fri, 18 Dec 2009 19:00:48 +0100, Alf P. Steinbach wrote: > In fact almost no Python > code does, but then it seems that people are not aware of how many of > their names are constants and think that they're uppercasing constants > when in fact they're not. E.g. routine arguments Routine argum

Re: tarfiles usage on python 2.4.4

2009-12-18 Thread MRAB
tekion wrote: All, I am using tarfile module and my python is version 2.4.4. When I call method extractall, I am getting error method does not exist. Could someone confirm if the method exist on python 2.4.4? Thanks It's new in Python 2.5. -- http://mail.python.org/mailman/listinfo/python-list

Re: Raw string substitution problem

2009-12-18 Thread MRAB
Gregory Ewing wrote: MRAB wrote: In simple cases you might be replacing with the same string every time, but other cases you might want the replacement to contain substrings captured by the regex. But you can give it a function that has access to the match object and can produce whatever repl

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Steven D'Aprano
On Sat, 19 Dec 2009 01:25:48 +0100, Alf P. Steinbach wrote: > That said, and a bit off-tangent to your comment's main thrust, the time > spent on coding that repeated-division-by-2 optimization would, I think, > be better spent googling "Collatz Conjecture" -- avoiding writing > /any/ code. ;-)

Re: Cookie name and expiration

2009-12-18 Thread ShoqulKutlu
I'd already found my problem, that I had to set the "path" propert of a cookie object something like below: myCookie.path = '/' This is not the cookie content and not documented in the mod_python cookie module documentation. I hope this will help anyone else.. Regards, Kutlu On Nov 26, 1:32 a

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Alf P. Steinbach
* Steven D'Aprano: On Fri, 18 Dec 2009 19:00:48 +0100, Alf P. Steinbach wrote: In fact almost no Python code does, but then it seems that people are not aware of how many of their names are constants and think that they're uppercasing constants when in fact they're not. E.g. routine arguments

Re: AttributeError: logging module bug ?

2009-12-18 Thread Peter
./of/logger.py from logging import Formatter class RootFormatter(Formatter): pass class ModuleFormatter(Formatter): pass class ClassFormatter(Formatter): pass class DataFormatter(Formatter): pass (and an empty ./of/__init__.py) your initial script runs without error. If yo

Re: Webpy and UnicodeDecodeError

2009-12-18 Thread Dave Angel
Oscar Del Ben wrote: You'll notice that one of the strings is a unicode one, and another one has the character 0x82 in it. Once join() discovers Unicode, it needs to produce a Unicode string, and by default, it uses the ASCII codec to get it. If you print your 'l' list (bad name, by the way,

Re: Raw string substitution problem

2009-12-18 Thread Steven D'Aprano
On Sat, 19 Dec 2009 02:24:00 +, MRAB wrote: > Gregory Ewing wrote: >> MRAB wrote: >> >>> In simple cases you might be replacing with the same string every >>> time, but other cases you might want the replacement to contain >>> substrings captured by the regex. >> >> But you can give it a fun

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread John Bokma
Steven D'Aprano writes: > CPython 2.5 and on has a keyhole optimizer that replaces many constant ^^^ Shouldn't that be peephole? > expressions with pre-computed values. And that's called constant folding. Unless I misread your post (or have been out of touch wit

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Alf P. Steinbach
* Steven D'Aprano: On Sat, 19 Dec 2009 01:25:48 +0100, Alf P. Steinbach wrote: That said, and a bit off-tangent to your comment's main thrust, the time spent on coding that repeated-division-by-2 optimization would, I think, be better spent googling "Collatz Conjecture" -- avoiding writing /a

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Steven D'Aprano
On Fri, 18 Dec 2009 15:26:05 -0800, Mensanator wrote: >> The second deviation is that since most names are constants, > > Really? Does that mean you don't use literals, to save the time required > to convert them to integers? Isn't that done at compile time? > > So, instead of doing the Collatz

Re: Creating Classes

2009-12-18 Thread Dave Angel
seafoid wrote: Hey Guys, I have started to read over classes as a brief respite from my parsing problem. When a class is defined, how does the class access the data upon which the class should act? Example: class Seq: def _

Re: Seek support for new slice syntax PEP.

2009-12-18 Thread Nobody
On Fri, 18 Dec 2009 09:49:26 -0500, Colin W. wrote: > You don't say, but seem to imply that the slice components include None. That's how missing components are implemented at the language level: > class foo: = def __getitem__(self, s): = return s =

Re: Creating Classes

2009-12-18 Thread Alf P. Steinbach
* Dave Angel -> seafoid: One other point: you should always derive a class from some other class, or 'object' by default. So you should being the class definition by: class Seq(object): Why? It mainly has to do with super(). But in any case if you omit the 'object' it's an "old style"

Re: Creating Classes

2009-12-18 Thread Dave Angel
Alf P. Steinbach wrote: * Dave Angel -> seafoid: One other point: you should always derive a class from some other class, or 'object' by default. So you should being the class definition by: class Seq(object): Why? It mainly has to do with super(). But in any case if you omit the 'o

Re: iterators and views of lists

2009-12-18 Thread Gregory Ewing
Terry Reedy wrote: On the other hand, Python indexes are a form of random access iterator, the top of the hierarchy. The term "random access iterator" seems oxymoronic to me. Iteration is all about operating on things in sequence. If you're accessing elements arbitrarily, then you're not iterat

Re: Dangerous behavior of list(generator)

2009-12-18 Thread Gregory Ewing
Albert van der Horst wrote: An important feature that is not documented is a severe defect. This isn't something that I would expect to find documented under the heading of generator expressions, because it doesn't have anything to do with them. It's an interaction between the iterator protoco

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Gregory Ewing
Mensanator wrote: Really? Does that mean you don't use literals, to save the time required to convert them to integers? I think all he means is that when he *does* use a named constant, he spells it in lower case rather than upper case, e.g. 'twopi' rather than 'TWOPI'. I don't think there's a

Re: shouldn't list comprehension be faster than for loops?

2009-12-18 Thread Gregory Ewing
Ryan Kelly wrote: Someone else wrote: It will be the same as the difference between a for loop and a call to map. Not so. If you use the "dis" module to peek at the bytecode generated for a list comprehension, you'll see it's very similar to that generated for an explicit for-loop. The usua

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Steven D'Aprano
On Fri, 18 Dec 2009 21:29:27 -0600, John Bokma wrote: > Steven D'Aprano writes: > >> CPython 2.5 and on has a keyhole optimizer that replaces many constant > ^^^ > Shouldn't that be peephole? Alternate names for the same thing. >> expressions with pre-computed va

Re: iterators and views of lists

2009-12-18 Thread Brendan Miller
On Fri, Dec 18, 2009 at 2:47 PM, Bearophile wrote: > Brendan Miller: >> I agree though, it doesn't matter to everyone and anyone. The reason I >> was interested was because i was trying to solve some specific >> problems in an elegant way. I was thinking it would be cool to make >> python more usa

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Steven D'Aprano
On Sat, 19 Dec 2009 04:04:51 +0100, Alf P. Steinbach wrote: > * Steven D'Aprano: >> On Fri, 18 Dec 2009 19:00:48 +0100, Alf P. Steinbach wrote: >> >>> In fact almost no Python >>> code does, but then it seems that people are not aware of how many of >>> their names are constants and think that th

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Mensanator
On Dec 18, 6:25 pm, "Alf P. Steinbach" wrote: > * Mensanator: > > >> The second deviation is that since most names are constants, > > > Really? Does that mean you don't use literals, to save the time > > required to convert them to integers? Isn't that done at compile > > time? > > > So, instead o

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Alf P. Steinbach
* Mensanator: That said, and a bit off-tangent to your comment's main thrust, the time spent on coding that repeated-division-by-2 optimization would, I think, be better spent googling "Collatz Conjecture" -- avoiding writing /any/ code. ;-) Ha! I know more about Collatz than you can ever fi

Re: Sort the values of a dict

2009-12-18 Thread Lie Ryan
On 12/19/2009 9:34 AM, mattia wrote: Can you provide me a much pythonic solution (with comments if possible, so I can actually learn something)? If you only need to get i'th element sometimes, sorting the dict is fine. Otherwise, you might want to use collections.OrderedDict. -- http://mail.p

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Mensanator
On Dec 19, 12:21 am, "Alf P. Steinbach" wrote: > * Mensanator: > > > > >> That said, and a bit off-tangent to your comment's main thrust, the time > >> spent > >> on coding that repeated-division-by-2 optimization would, I think, be > >> better > >> spent googling "Collatz Conjecture"  --  avoid

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - RequestFor Comments

2009-12-18 Thread Lie Ryan
On 12/19/2009 12:56 PM, Steven D'Aprano wrote: As far as I know, no programming language provides a standard facility for renaming entities, be they data or routines: The C-preprocessor does to C/C++, in a limited fashion. -- http://mail.python.org/mailman/listinfo/python-list

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Steven D'Aprano
On Sat, 19 Dec 2009 04:29:22 +0100, Alf P. Steinbach wrote: > * Steven D'Aprano: >> On Sat, 19 Dec 2009 01:25:48 +0100, Alf P. Steinbach wrote: >> >>> That said, and a bit off-tangent to your comment's main thrust, the >>> time spent on coding that repeated-division-by-2 optimization would, I >>>

Anybody use web2py?

2009-12-18 Thread AppRe Godeck
Just curious if anybody prefers web2py over django, and visa versa. I know it's been discussed on a flame war level a lot. I am looking for a more intellectual reasoning behind using one or the other. -- http://mail.python.org/mailman/listinfo/python-list

Re: Object Relational Mappers are evil (a meditation)

2009-12-18 Thread Lie Ryan
On 12/17/2009 3:17 PM, J Kenneth King wrote: A language is a thing. It may have syntax and semantics that bias it towards the conventions and philosophies of its designers. But in the end, a language by itself would have a hard time convincing a human being to adopt bad practises. Perhaps som

Re: iterators and views of lists

2009-12-18 Thread Lie Ryan
On 12/17/2009 4:44 AM, Francesco Bochicchio wrote: On Dec 16, 1:58 pm, Anh Hai Trinh wrote: You might be interested in this library. You can easily create arbitrary "slice", for example i = mylist>> takei(primes()) will return an iterator over the i

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Alf P. Steinbach
* Steven D'Aprano: On Sat, 19 Dec 2009 04:04:51 +0100, Alf P. Steinbach wrote: * Steven D'Aprano: On Fri, 18 Dec 2009 19:00:48 +0100, Alf P. Steinbach wrote: In fact almost no Python code does, but then it seems that people are not aware of how many of their names are constants and think tha

Re: Programming intro book ch1 and ch2 (Windows/Python 3) - Request For Comments

2009-12-18 Thread Alf P. Steinbach
* Steven D'Aprano: On Sat, 19 Dec 2009 04:29:22 +0100, Alf P. Steinbach wrote: * Steven D'Aprano: On Sat, 19 Dec 2009 01:25:48 +0100, Alf P. Steinbach wrote: That said, and a bit off-tangent to your comment's main thrust, the time spent on coding that repeated-division-by-2 optimization woul

<    1   2