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

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

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

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

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

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: 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: 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: 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: 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: Raw string substitution problem

2009-12-18 Thread Gregory Ewing
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 replacement string it want

Re: Sort the values of a dict

2009-12-18 Thread Rory Campbell-Lange
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 i-th element of the

Acceesing python httplib2 over a network share in windows 7

2009-12-18 Thread aj
I am trying to run python from a network share on windows 7. The network share is T: >t:\python-2.6.1\python Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import httpl

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

2009-12-18 Thread 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) if f>0: a =

Re: Sort the values of a dict

2009-12-18 Thread mattia
Il Fri, 18 Dec 2009 18:00:42 -0500, David Robinow ha scritto: > On Fri, Dec 18, 2009 at 5:34 PM, mattia 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 t

Re: Sort the values of a dict

2009-12-18 Thread David Robinow
On Fri, Dec 18, 2009 at 5:34 PM, mattia 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 i-th element of the l

Re: iterators and views of lists

2009-12-18 Thread Bearophile
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 usable in programming competitions by giving it its own > por

Re: Sort the values of a dict

2009-12-18 Thread mattia
Actually, in order to use duplicate values I need something like: >>> import copy >>> d = {1:('a', 1, 12), 5:('r', 21, 10), 2:('u', 9, 8), 3:('u', 9, 8) } >>> dc = copy.deepcopy(d) >>> t = [x for x in d.values()] >>> def third(mls): ... return mls[2] ... >>> s = sorted(t, key=third) >>> pres =

Re: Sort the values of a dict

2009-12-18 Thread Chris Kaynor
I'd write it as: s = sorted(d.iteritems(), key=lambda i: i[1][2]) If using python 3, it should be d.items() instead of d.iteritems(). d.iteritems() is a generator yielding tuples of (key, value) from the dictionary 'd'. lambda i: i[1][2] is the same as: def sort_(i): return i[1][2] but in-lin

Sort the values of a dict

2009-12-18 Thread mattia
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 i-th element of the list. I'm not that good at python (v3.1), but this is

Re: Setting Parameters inside of code

2009-12-18 Thread David Robinow
On Fri, Dec 18, 2009 at 10:46 AM, Jim Valenza wrote: > Hello All - I have a very novice question for any of you out there.  I need > to assign several parameters to a code in python. I have an example of a > code that was in DOS that I would need to set as parameters in my Python > script. > > Set

Re: Setting Parameters inside of code

2009-12-18 Thread Terry Reedy
On 12/18/2009 10:46 AM, Jim Valenza wrote: Hello All - I have a very novice question for any of you out there. I need to assign several parameters to a code in python. In Python, a 'parameter' is a function local name defined in the header of the function and bound to an argument when the fun

Re: iterators and views of lists

2009-12-18 Thread Terry Reedy
On 12/18/2009 1:00 AM, Brendan Miller wrote: For the benefit of those of us who aren't C++ programmers, what do its iterators do that Python's don't? It depends on what one means by 'iterator'. Python iterators do not fit in the STL hierarchy. On the other hand, Python indexes are a form of

Re: PyArg_ParseTupleAndKeywords in Python3.1

2009-12-18 Thread casevh
On Dec 18, 10:28 am, Joachim Dahl wrote: > My mistake seems to be that I declared > > char a, b; > > instead of > > int a, b; > > Thank you for sorting this out. > > Joachim I think you need to initialize them, too. -- http://mail.python.org/mailman/listinfo/python-list

Re: Line indexing in Python

2009-12-18 Thread seafoid
Rory, You are a gentleman! Thank you very much for your suggestion! Kind Regards, Seafoid. Rory Campbell-Lange wrote: > > On 18/12/09, seafoid (fitzp...@tcd.ie) wrote: >> http://old.nabble.com/Parsing-file-format-to-ensure-file-meets-criteria-to26837682.html > > Your specification is confus

Re: Line indexing in Python

2009-12-18 Thread seafoid
Hey folks, Is it possible to assign a list within a nested list to a variable? Example: l = [['1', '2', '3'], ['4', '5', '6']] for i in l: if i[0][1] == '1': m = i Indeed, I generally do not understand how to assign variables within a loop! Is there an easy way to 'flatten' a nes

Re: Line indexing in Python

2009-12-18 Thread Rory Campbell-Lange
On 18/12/09, seafoid (fitzp...@tcd.ie) wrote: > http://old.nabble.com/Parsing-file-format-to-ensure-file-meets-criteria-to26837682.html Your specification is confusing. However I suggest you break it down the code so that the steps in your programme are logical. Good luck. # example psuedocode he

Re: Creating Classes

2009-12-18 Thread seafoid
Steve, that has indeed clarified matters! Thanks! -- View this message in context: http://old.nabble.com/Creating-Classes-tp26848375p26849864.html Sent from the Python - python-list mailing list archive at Nabble.com. -- http://mail.python.org/mailman/listinfo/python-list

Re: iterators and views of lists

2009-12-18 Thread Brendan Miller
On Fri, Dec 18, 2009 at 10:39 AM, Carl Banks wrote: > On Dec 17, 10:00 pm, Brendan Miller wrote: >> On Thu, Dec 17, 2009 at 6:44 PM, Steven D'Aprano >> >> wrote: >> > On Thu, 17 Dec 2009 12:07:59 -0800, Brendan Miller wrote: >> >> >> I was thinking it would be cool to make python more usable in

Re: Creating Classes

2009-12-18 Thread Steve Holden
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:

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

2009-12-18 Thread Brian J Mingus
On Fri, Dec 18, 2009 at 11:55 AM, sturlamolden wrote: > On 17 Des, 18:37, Carlos Grohmann wrote: > > > 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. > > > > thoughts? > > Let me as

Re: iterators and views of lists

2009-12-18 Thread Alf P. Steinbach
* Carl Banks: On Dec 18, 11:08 am, "Alf P. Steinbach" wrote: * Carl Banks: On Dec 17, 10:00 pm, Brendan Miller wrote: On Thu, Dec 17, 2009 at 6:44 PM, Steven D'Aprano wrote: On Thu, 17 Dec 2009 12:07:59 -0800, Brendan Miller wrote: I was thinking it would be cool to make python more us

Re: Help with invoking standard mail app in windows

2009-12-18 Thread Kev Dwyer
On Sat, 19 Dec 2009 06:36:32 +1100, Astan Chee wrote: > Kev Dwyer wrote: >> Hello Astan, >> >> Your code executes without error for me on Win98 (!) with Python 2.5 or >> XP with Python 2.6. >> >> It would help people to help you if you could provide the *exact* >> console output from when you try

Re: How Do I...?

2009-12-18 Thread Tim Chase
Victor Subervi wrote: How do I...? Well, you start by reading a book on how to program. You would then learn that what you want (in all likelihood) is a dictionary/map structure for dynamically created key/value pairs. Once you have progressed from your current apprenticeship and achieved

Re: How Do I...?

2009-12-18 Thread Victor Subervi
On Fri, Dec 18, 2009 at 3:46 PM, Rami Chowdhury wrote: > On Fri, Dec 18, 2009 at 10:55, Victor Subervi > wrote: > > Hi; > > I have this code: > > > > i = 0 > > nameNos = [] > > nos = [] > > for option in ourOptions(): > > nameNos.append('optionNo%d' % i) > > nos.append

Re: How Do I...?

2009-12-18 Thread Rami Chowdhury
On Fri, Dec 18, 2009 at 10:55, Victor Subervi wrote: > Hi; > I have this code: > >     i = 0 >     nameNos = [] >     nos = [] >     for option in ourOptions(): >   nameNos.append('optionNo%d' % i) >   nos.append(i) >   i += 1 > > The idea is that through every iteration of option, I c

Re: Help with invoking standard mail app in windows

2009-12-18 Thread Astan Chee
Kev Dwyer wrote: Hello Astan, Your code executes without error for me on Win98 (!) with Python 2.5 or XP with Python 2.6. It would help people to help you if you could provide the *exact* console output from when you try to execute the code, *including* the traceback. That way we can work

Re: iterators and views of lists

2009-12-18 Thread Carl Banks
On Dec 18, 11:08 am, "Alf P. Steinbach" wrote: > * Carl Banks: > > > > > On Dec 17, 10:00 pm, Brendan Miller wrote: > >> On Thu, Dec 17, 2009 at 6:44 PM, Steven D'Aprano > > >> wrote: > >>> On Thu, 17 Dec 2009 12:07:59 -0800, Brendan Miller wrote: > I was thinking it would be cool to make p

Re: Design question about pretree classifier

2009-12-18 Thread Julian
On 18 Dez., 18:59, Steve Holden wrote: > Julian wrote: > > Hello, > > > I've got a design problem for a classifier. To make it short: it maps > > strings on strings. > > > Some strings have exactly one classification, some none and some more > > than one. > > > There's a method classify(self, word

Re: iterators and views of lists

2009-12-18 Thread Lie Ryan
On 12/18/2009 7:07 AM, Brendan Miller wrote: As for copying pointers not taking much time... that depends on how long the list is. if you are working with small sets of data, you can do almost anything and it will be efficient. However, if you have megabytes or gigabytes of data (say you are work

Creating Classes

2009-12-18 Thread seafoid
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 __init__(self, dat

Re: Help with invoking standard mail app in windows

2009-12-18 Thread Kev Dwyer
On Sat, 19 Dec 2009 04:56:34 +1100, Astan Chee wrote: > Hi, > I don't know if my last mail made it or not but here it is again. I'm > trying to launch standard mail app in windows and after looking around > most look like this: > > import urllib, webbrowser, win32api > def mailto_url(to=None,subj

Re: iterators and views of lists

2009-12-18 Thread Alf P. Steinbach
* Carl Banks: On Dec 17, 10:00 pm, Brendan Miller wrote: On Thu, Dec 17, 2009 at 6:44 PM, Steven D'Aprano wrote: On Thu, 17 Dec 2009 12:07:59 -0800, Brendan Miller wrote: I was thinking it would be cool to make python more usable in programming competitions by giving it its own port of the

Re: subprocess.Popen and ordering writes to stdout and stderr

2009-12-18 Thread Lie Ryan
On 12/18/2009 8:15 AM, Chris Withers wrote: the order of the writes isn't preserved. How can I get this to be the case? You'll need to flush the std{out|err} or set them unbuffered; or you can just forget about relying on std{out|err} being ordered per write-order. -- http://mail.python

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

2009-12-18 Thread sturlamolden
On 17 Des, 18:37, Carlos Grohmann wrote: > 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. > > thoughts? Let me ask a retoric question: - How much do you really value 20 ms of CPU time

How Do I...?

2009-12-18 Thread Victor Subervi
Hi; I have this code: i = 0 nameNos = [] nos = [] for option in ourOptions(): nameNos.append('optionNo%d' % i) nos.append(i) i += 1 The idea is that through every iteration of option, I can create a new variable such as 'optionNo0', 'optionNo1' etc and assign val

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

2009-12-18 Thread Carl Banks
On Dec 17, 9:37 am, Carlos Grohmann wrote: > 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. > > thoughts? You shouldn't trust your intuition in things like this. Some features were add

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

2009-12-18 Thread sturlamolden
On 17 Des, 18:42, "Alf P. Steinbach" wrote: > Have you tried this with > >    dip1 = [dp - 0.01 if dp == 90 else dp for dp in dipList] And for comparison with map: map(lambda dp: dp - 0.01 if dp == 90 else dp, dipList) -- http://mail.python.org/mailman/listinfo/python-list

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

2009-12-18 Thread sturlamolden
On 17 Des, 18:37, Carlos Grohmann wrote: > 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. > > thoughts? Anything else being equal, list comprehensions will be the faster becuase they i

Re: How to create a docstring for a module?

2009-12-18 Thread Albert van der Horst
In article , alex23 wrote: >"Phillip M. Feldman" wrote: >> It does seem as though IPython could be a bit more clever about this. =A0 > >I disagree. I _like_ that IPython is only reporting on the current >state of the interpreter and not trying to second guess what I meant. > >> If the user asks

Re: iterators and views of lists

2009-12-18 Thread Carl Banks
On Dec 17, 10:00 pm, Brendan Miller wrote: > On Thu, Dec 17, 2009 at 6:44 PM, Steven D'Aprano > > wrote: > > On Thu, 17 Dec 2009 12:07:59 -0800, Brendan Miller wrote: > > >> I was thinking it would be cool to make python more usable in > >> programming competitions by giving it its own port of th

Re: Line indexing in Python

2009-12-18 Thread Rory Campbell-Lange
On 18/12/09, seafoid (fitzp...@tcd.ie) wrote: > Have you any suggestions how I may render this code undead or should I scrap > it and create something new? It might be easier for us to help you if you give us an example of your input file and a clearer description of what you are trying to do with

Re: Raw string substitution problem

2009-12-18 Thread Lie Ryan
On 12/19/2009 4:59 AM, Alan G Isaac wrote: On 12/18/2009 12:17 PM, 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. Of course that "conversion" is needed in the repla

Using PyImport_ExtendInittab with package

2009-12-18 Thread Julien Danjou
Hi, I'm trying to embed Python and therefore use PyImport_ExtendInittab() to register modules. My current problem is that, if it works well with a simple module "hello", naming a module "hello.foobar" in the inittab struct does not seems to work. imp.find_module("hello.foobar") returns correctly t

Re: Line indexing in Python

2009-12-18 Thread seafoid
Hi Guys, It has been point out that it is difficult for anyone to provide suggestions if I do not outline more clearly my input file and an example of what I wish to do with it (Thanks Rory!). I mentioned it in this thread (Is creating different threads bad etiquette? If so, lesson learned!): h

Re: Line indexing in Python

2009-12-18 Thread Lie Ryan
On 12/19/2009 4:33 AM, seafoid wrote: Thanks for that Lie. I had to have a think about what you meant when you referred to control going to a.write(line). and if-elif-elif-... chain is executed sequentially and when a match is found, the rest of the chain is skipped. Your code: if line.sta

Re: Another MySQL Problem

2009-12-18 Thread John Nagle
MRAB wrote: Victor Subervi wrote: Hi; mysql> truncate tem126072414516; Query OK, 0 rows affected (0.00 sec) Then I run a script: if whatDo == 'insert': try: sql = 'insert into %s (ProdID, Quantity) values ("%s", "%s");' % (tmpTable, prodid, quantity) print sql cursor

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

2009-12-18 Thread Alf P. Steinbach
I finally finished (draft), I believe!, chapter 2... Chapter 1 gets the reader up & running, i.e. it's "Hello, world!", basic tool usage, without discussing anything about programming really. One reaction to this chapter, based on the two example programs in it, was that it wasn't gradual and

Re: [ANN] pylint 0.19 / astng 0.19.2

2009-12-18 Thread David Robinow
On Fri, Dec 18, 2009 at 12:49 PM, Jean-Michel Pichavant wrote: > Jerry Hill wrote: >> >> On Fri, Dec 18, 2009 at 12:24 PM, Jean-Michel Pichavant >  File >>> "/opt/tools/python/python2.3/site-packages/logilab_astng-0.19.2-py2.5.egg/logilab/astng/infutils.py", >>> line 28, in >>>  from logilab.astn

Re: Design question about pretree classifier

2009-12-18 Thread Steve Holden
Julian wrote: > Hello, > > I've got a design problem for a classifier. To make it short: it maps > strings on strings. > > Some strings have exactly one classification, some none and some more > than one. > > There's a method classify(self, word) wich classifies a word. For the > first case ther

Re: Raw string substitution problem

2009-12-18 Thread Alan G Isaac
On 12/18/2009 12:17 PM, 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. Of course that "conversion" is needed in the replacement. But e.g. Vim substitutions handle th

Re: Raw string substitution problem

2009-12-18 Thread Alan G Isaac
On 12/17/2009 7:59 PM, Rhodri James wrote: "re.compile('a\\nc')" passes a sequence of four characters to re.compile: 'a', '\', 'n' and 'c'. re.compile() then does it's own interpretation: 'a' passes through as is, '\' flags an escape which combined with 'n' produces the newline character (0x0a),

Re: [ANN] pylint 0.19 / astng 0.19.2

2009-12-18 Thread Sylvain Thénault
On 18 décembre 18:24, Jean-Michel Pichavant wrote: > Sylvain Thénault wrote: > >Hi, > > > >I'm very pleased to announce the release of pylint 0.19 / astng 0.19.2 > >release! > > > >More information / download on http://www.logilab.org/project/pylint/0.19.0. > > > >This is a "community" release, i

Help with invoking standard mail app in windows

2009-12-18 Thread Astan Chee
Hi, I don't know if my last mail made it or not but here it is again. I'm trying to launch standard mail app in windows and after looking around most look like this: import urllib, webbrowser, win32api def mailto_url(to=None,subject=None,body=None,cc=None): """ encodes the content as a ma

Re: [ANN] pylint 0.19 / astng 0.19.2

2009-12-18 Thread Jean-Michel Pichavant
Jerry Hill wrote: On Fri, Dec 18, 2009 at 12:24 PM, Jean-Michel Pichavant > File "/opt/tools/python/python2.3/site-packages/logilab_astng-0.19.2-py2.5.egg/logilab/astng/infutils.py", line 28, in from logilab.astng._nodes import Proxy_, List, Tuple, Function, If, TryExcept ImportError: No

Re: imports in __init__.py

2009-12-18 Thread Peter Otten
Phil wrote: > I wrote my last message late last night. When I said "I am unable to > import a module from the package without an import error.", I did mean > the 'modulename' module. > > However, I just set up a Debian VM with Python 2.5.2 and what I was > trying to do works. So it is either some

Re: Line indexing in Python

2009-12-18 Thread seafoid
Thanks for that Lie. I had to have a think about what you meant when you referred to control going to a.write(line). Have you any suggestions how I may render this code undead or should I scrap it and create something new? My confusion and ineptitude is perhaps explained by my being a biologist

Re: [ANN] pylint 0.19 / astng 0.19.2

2009-12-18 Thread Jerry Hill
On Fri, Dec 18, 2009 at 12:24 PM, Jean-Michel Pichavant >  File > "/opt/tools/python/python2.3/site-packages/logilab_astng-0.19.2-py2.5.egg/logilab/astng/infutils.py", > line 28, in >   from logilab.astng._nodes import Proxy_, List, Tuple, Function, If, > TryExcept > ImportError: No module named _

Re: share dictionary between processes

2009-12-18 Thread Steve Holden
blumenkraft wrote: > Hi, > > I want to share dictionary between two distinct processes. > > > Something like this: > > first.py > import magic_share_module > > def create_dictionary(): > return {"a": 1} > > magic_share_module.share("shared_dictionary", > creator.create_dictionary) > while

  1   2   >