Re: [Tutor] creating a tab delimited filename

2005-03-17 Thread Kent Johnson
C Smith wrote: Here's an example that cycles through 3 number, 0, 1, and 2: ### j=0 for i in range(10): .. print j .. j = (j+1)%3 .. 0 1 2 0 1 2 0 1 2 0 ### A nice way to do this is with itertools.cycle(): import itertools cyc = itertools.cycle(range(3)) for i in range(10): ...

Re: [Tutor] cyclically rotate a seq

2005-03-17 Thread Kent Johnson
kevin parks wrote: Hi folks, I am trying to cyclically rotate a seq until it reached the beginning stage again. I would like to be able BTW collections.deque supports most list methods and rotate(): http://docs.python.org/lib/module-collections.html Kent

Re: [Tutor] How to delete a class instance

2005-03-17 Thread Kent Johnson
Kent Johnson wrote: Shitiz Bansal wrote: In the code you have shown, I don't see any need for the queue. Just create the thread and start it. I don't think you have to keep a reference to it. I'm not sure, but I think the thread will be garbage collected when it completes. (Can anyone else

[Tutor] Unreadable code explanation

2005-03-17 Thread Mark Kels
Hi list. I have downloaded some code from useless python that was writen buy a guy named Sammy Mannaert. The code should show that python can be unreadable, and it really is... Can anyone explain to me how does this thing works ?? Here is the code (it prints python readable ?): f=lambda

[Tutor] Can Python work like SAS Data Step

2005-03-17 Thread Edie Duff
Can Python work like the SAS (Data Step), where you read in external data (sequential, ms access, sql) define file layout to Python and be able to write code where you produce a customize report with title and columns headings, subtotals and totals and write that report out has afile? And if it

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
applause Very nice sir. I'm interested in what you're doing here with the caret metacharacter. For one thing, why enclose it and the whitespace flag within a character class? Does this not traditionally mean you want to strip a metacharacter of it's special meaning? On Mar 16, 2005, at 8:00

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
On Mar 16, 2005, at 8:32 PM, Kent Johnson wrote: in (.*?)\b will match against in because you use .* which will match an empty string. Try in (.+?)\b (or (?=\bin)..+?\b )to require one character after the space. Another working example, excellent. I'm not too clear on why the back to back ..

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
I don't have that script on my system, but I may put pythoncard on here and run it through that: http://pythoncard.sourceforge.net/samples/redemo.html Although regexPlor looks like it has the same functionality, so I may just go with that. Thanks. On Mar 17, 2005, at 1:31 AM, Michael Dunn

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Kent Johnson
Mike Hall wrote: On Mar 16, 2005, at 8:32 PM, Kent Johnson wrote: in (.*?)\b will match against in because you use .* which will match an empty string. Try in (.+?)\b (or (?=\bin)..+?\b )to require one character after the space. Another working example, excellent. I'm not too clear on why the

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Mike Hall
On Mar 17, 2005, at 11:11 AM, Kent Johnson wrote: The first one matches the space after 'in'. Without it the .+? will match the single space, then \b matches the *start* of the next word. I think I understand. Basically the first dot advances the pattern forward in order to perform a non-greedy

Re: [Tutor] stopping greedy matches

2005-03-17 Thread Kent Johnson
Mike Hall wrote: On Mar 17, 2005, at 11:11 AM, Kent Johnson wrote: The first one matches the space after 'in'. Without it the .+? will match the single space, then \b matches the *start* of the next word. I think I understand. Basically the first dot advances the pattern forward in order to

Re: [Tutor] big numbers

2005-03-17 Thread Hugo González Monteverde
Yes, it is: http://python.fyxm.net/peps/pep-0237.html Robert Storey wrote: This book is a few years old and was written for Python version 1.5, and of course I'm using version 2.3, so I'm just wondering if this whole issue of big numbers is now being handled automatically? This is my first post -

Re: [Tutor] unicode

2005-03-17 Thread Danny Yoo
On Mon, 14 Mar 2005, Stefan Elwesthal wrote: I'm swedish, our databae is full of horrible characters with strange dots on top and Python won't have none of it. it falls apart telling me that it can't decode that sort of thingy! So.. will I have to do some terrible magic storing all single

[Tutor] primes

2005-03-17 Thread Gregor Lingl
Hi! Who knows a more concise or equally concise but more efficient expression, which returns the same result as [x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]] Gregor P.S.: ... or a more beautiful one ;-) ___ Tutor maillist -

[Tutor] subclassing across multiple modules

2005-03-17 Thread Brian van den Broek
Hi all, I'm uncertain of how to make use of OOP design across multiple modules. (Actually, on reflection, I'm not certain the multiple modules aspect is central.) I'm also uncertain of how to frame the question well, so please bear with me :-) A schematic of what I have (with fake names for

Re: [Tutor] primes

2005-03-17 Thread Max Noel
On Mar 17, 2005, at 22:28, Gregor Lingl wrote: Hi! Who knows a more concise or equally concise but more efficient expression, which returns the same result as [x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]] Gregor P.S.: ... or a more beautiful one ;-) Hmm... I don't have

Re: [Tutor] primes

2005-03-17 Thread jfouhy
Quoting Gregor Lingl [EMAIL PROTECTED]: [x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]] Heh. That's quite neat. I can only offer one suggestion --- if you replace range with xrange, you get a small speed improvement. eg: On my system, it took 415 seconds to generate a list

Re: [Tutor] primes

2005-03-17 Thread Danny Yoo
On Thu, 17 Mar 2005, Gregor Lingl wrote: Hi! Who knows a more concise or equally concise but more efficient expression, which returns the same result as [x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]] Hi Gregor, Here is one that's traduced... er... adapted from

[Tutor] Re: primes

2005-03-17 Thread André Roberge
[EMAIL PROTECTED] wrote: Quoting Gregor Lingl [EMAIL PROTECTED]: [x for x in range(2,100) if not [y for y in range(2,x) if x%y==0]] Heh. That's quite neat. I can only offer one suggestion --- if you replace range with xrange, you get a small speed improvement. eg: On my system, it took 415

Re: [Tutor] primes

2005-03-17 Thread Max Noel
On Mar 17, 2005, at 23:54, Danny Yoo wrote: Hi Gregor, Here is one that's traduced... er... adapted from material from the classic textbook Structure and Interpretation of Computer Programs: SNIP Ooh, nifty. Okay, I decided to learn how to use the timeit module, so I used it to compare my

[Tutor] subclassing across multiple modules

2005-03-17 Thread Lloyd Kvam
You want a method in a base class to parse input and create instances of certain derived classes. Your sample code looks like: if some_condition_on_chunk_contents: node = Node1(chunk_contents) else: node = Node2(chunk_contents) I'd suggest changing the method to use a variable to

Re: [Tutor] primes

2005-03-17 Thread Kent Johnson
Max Noel wrote: #!/usr/bin/env python import math import timeit def primeConcise(limit): return [2] + [x for x in xrange(3, limit, 2) if not [y for y in [2] + range(3,x,2) if x%y==0]] def primeConciseOptimized(limit): return [2] + [x for x in xrange(3, limit, 2) if not [y for y in [2] +

[Tutor] Re: subclassing across multiple modules

2005-03-17 Thread Brian van den Broek
Hi all, Thanks for the reply, Lloyd. Lloyd Kvam said unto the world upon 2005-03-17 20:36: You want a method in a base class to parse input and create instances of certain derived classes. Not quite. One class (Tree) parses a file and creates instances of Node1 and Node2 (derived from Node). None

Re: [Tutor] subclassing across multiple modules

2005-03-17 Thread Brian van den Broek
Kent Johnson said unto the world upon 2005-03-17 20:44: Brian van den Broek wrote: A schematic of what I have (with fake names for ease of example) is a base module Toolkit.py and I want to write a module Application.py which specializes the behaviour of the Toolkit.py classes. (I'm using

Re: [Tutor] primes

2005-03-17 Thread C Smith
On Thursday, Mar 17, 2005, at 17:49 America/Chicago, [EMAIL PROTECTED] wrote: On my system, it took 415 seconds to generate a list of primes 50,000 using range, but only 386 seconds if I use the same code, but with xrange instead. If you only calculate y up to sqrt(x) you will see a dramatic

Re: [Tutor] primes

2005-03-17 Thread Sean Perry
Danny Yoo wrote: Here is one that's traduced... er... adapted from material from the classic textbook Structure and Interpretation of Computer Programs: ## from itertools import ifilter, count def notDivisibleBy(n): ... def f(x): ... return x % n != 0 ... return f ... def