Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Paul Rubin
Chris Torek writes: > def primes(): > """ > Yields sequence of prime numbers via Sieve of Eratosthenes. > """ I think this has the same order-complexity but is enormously slower in practice, and runs out of recursion stack after a while. Exercise: spot the recursion. from iterto

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Chris Torek
Now that the exercise has been solved... Instead of "really short code to solve the problem", how about some "really long code"? :-) I was curious about implementing prime factorization as a generator, using a prime-number generator to come up with the factors, and doing memoization of the gener

Re: Security test of embedded Python

2011-06-21 Thread Dennis
Hi, The Google App Engine product seems to sandbox Python code, however it comes with a lot of limitations and maybe those can be an inspiration for how you design your infrastructure. http://code.google.com/appengine/docs/python/overview.html http://code.google.com/appengine/kb/commontasks.html

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Paul Rubin
Terry Reedy writes: > If the best C program for a problem takes 10 seconds or more, then > applying the same 1 minute limit to Python is insane, and contrary to > the promotion of good algorithm thinking. The Euler problems are all designed to be doable in 1 minute or less and the Euler project s

Re: Tkinter/scrollbar/canvas question

2011-06-21 Thread Chris Angelico
On Wed, Jun 22, 2011 at 1:50 PM, Saul Spatz wrote: > This is the third time I've tried to post this reply.  If you see multiple > answers from me, that's why. > All three came through on the mailing list, but out of order - this one came in second. Chris Angelico -- http://mail.python.org/mail

Re: Tkinter/scrollbar/canvas question

2011-06-21 Thread Saul Spatz
It works if you change it like so: from tkinter import * class ShowList(Frame): def __init__(self, root): Frame.__init__(self, root) self.grid() self.draw_widgets() def draw_widgets(self): cframe = Frame(self)

Re: Handling import errors

2011-06-21 Thread Chris Rebert
On Tue, Jun 21, 2011 at 1:51 PM, Guillaume Martel-Genest wrote: > What is the pythonic way to handle imports error? What is bugging me > is that the imports can't be inside a function (because I use them in > different places in the script and thus they have to be in the global > scope). I would w

Re: Emails backup in python 3.2

2011-06-21 Thread Michael Hrivnak
Why not use one of the many projects and products that are designed to store email? Do you have a special reason for wanting to implement your own email storage? I'm thinking that you can use fetchmail with your favorite mail store, and you won't need to write any code at all. http://fetchmail.b

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Terry Reedy
On 6/21/2011 8:00 PM, Paul Rubin wrote: Terry Reedy writes: efficient implementation will allow a solution to be obtained on a modestly powered computer in less than one minute." If something really takes a minute in C, allow yourself at least 10 minutes or even more with plain CPython. No.

Re: Tkinter/scrollbar/canvas question

2011-06-21 Thread Saul Spatz
This is the third time I've tried to post this reply. If you see multiple answers from me, that's why. Your script will work if you change it like so: from tkinter import * class ShowList(Frame): def __init__(self, root): Frame.__init__(self, root) self.g

Re: Unicode codepoints

2011-06-21 Thread Chris Angelico
On Wed, Jun 22, 2011 at 1:37 PM, Saul Spatz wrote: > Hi, > > I'm just starting to learn a bit about Unicode. I want to be able to read a > utf-8 encoded file, and print out the codepoints it encodes.  After many > false starts, here's a script that seems to work, but it strikes me as > awfully

Re: Tkinter/scrollbar/canvas question

2011-06-21 Thread Saul Spatz
It works if you change it like so: from tkinter import * class ShowList(Frame): def __init__(self, root): Frame.__init__(self, root) self.grid() self.draw_widgets() def draw_widgets(self): cframe = Frame(self)

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
On Jun 21, 10:02 pm, Mel wrote: > John Salerno wrote: > > ::sigh:: Well, I'm stuck again and it has to do with my get_factors > > function again, I think. Even with the slight optimization, it's > > taking forever on 20! (factorial, not excitement)  :) It's frustrating > > because I have the Pytho

Re: Security test of embedded Python

2011-06-21 Thread Paul Rubin
Chris Angelico writes: > Meanwhile, I'm looking into V8 and whether we can do everything we > need to that way, and how much dev time it's going to take me to > change languages... If you want to run Python, one obvious approach is a controlled-execution wrapper like Geordi uses. -- http://mail.

Unicode codepoints

2011-06-21 Thread Saul Spatz
Hi, I'm just starting to learn a bit about Unicode. I want to be able to read a utf-8 encoded file, and print out the codepoints it encodes. After many false starts, here's a script that seems to work, but it strikes me as awfully awkward and unpythonic. Have you a better way? def codePoints

Re: Security test of embedded Python

2011-06-21 Thread Chris Angelico
On Wed, Jun 22, 2011 at 1:09 PM, Benjamin Kaplan wrote: > Use Pyjamas with that and now you have your sandboxed Python :) > Not a day goes past without a reminder that I haven't yet explored Pyjamas! :) Monty's back online now in a restricted environment. I'm going to a meeting in a couple of ho

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
On Jun 21, 9:09 pm, Paul Rubin wrote: > John Salerno writes: > > It's frustrating because I have the Python right, but I'm getting > > stuck on the math > > "What is the smallest positive number that is evenly divisible by all > > of the numbers from 1 to 20?" > > The answer is lcm [1,2,3, ..

Re: Security test of embedded Python

2011-06-21 Thread Benjamin Kaplan
On Tue, Jun 21, 2011 at 7:40 PM, Paul Rubin wrote: > Chris Angelico writes: >> I'll also be looking into Pike. Unfortunately its community is far >> smaller than Python's, so security holes may be less obvious. > > Actually the most obvious and widespread sandboxed language these days > is Javasc

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Benjamin Kaplan
On Tue, Jun 21, 2011 at 4:30 PM, Terry Reedy wrote: > On 6/21/2011 3:48 PM, John Salerno wrote: > >> Absolutely not! Each problem has been designed according to a "one- >> minute rule", which means that although it may take several hours to >> design a successful algorithm with more difficult prob

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Mel
John Salerno wrote: > ::sigh:: Well, I'm stuck again and it has to do with my get_factors > function again, I think. Even with the slight optimization, it's > taking forever on 20! (factorial, not excitement) :) It's frustrating > because I have the Python right, but I'm getting stuck on the math

Re: Security test of embedded Python

2011-06-21 Thread Paul Rubin
Chris Angelico writes: > I'll also be looking into Pike. Unfortunately its community is far > smaller than Python's, so security holes may be less obvious. Actually the most obvious and widespread sandboxed language these days is Javascript. There's several embeddable implementations. Maybe you

Re: Security test of embedded Python

2011-06-21 Thread Chris Angelico
Followup: The test box has been administratively taken offline after about an hour of testing. Thank you to everyone who participated; it seems we have a lot of changes to make! Monty failed the test. But it was an incredibly successful test. And hopefully, we'll be bringing things back online for

Re: Security test of embedded Python

2011-06-21 Thread Chris Angelico
On Wed, Jun 22, 2011 at 12:02 PM, Paul Rubin wrote: > Chris Angelico writes: >> users to supply scripts which will then run on our servers... >> The environment is Python 3.3a0 embedded in C++, running on Linux. > > This doesn't sound like a bright idea, given the well-known difficulty > of sandb

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread MRAB
On 22/06/2011 02:21, John Salerno wrote: ::sigh:: Well, I'm stuck again and it has to do with my get_factors function again, I think. Even with the slight optimization, it's taking forever on 20! (factorial, not excitement) :) It's frustrating because I have the Python right, but I'm getting stu

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Paul Rubin
John Salerno writes: > It's frustrating because I have the Python right, but I'm getting > stuck on the math > "What is the smallest positive number that is evenly divisible by all > of the numbers from 1 to 20?" The answer is lcm [1,2,3, ... 20]. You can figure out how to implement lcm. Th

Re: Security test of embedded Python

2011-06-21 Thread Paul Rubin
Chris Angelico writes: > users to supply scripts which will then run on our servers... > The environment is Python 3.3a0 embedded in C++, running on Linux. This doesn't sound like a bright idea, given the well-known difficulty of sandboxing Python. Geordi

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
::sigh:: Well, I'm stuck again and it has to do with my get_factors function again, I think. Even with the slight optimization, it's taking forever on 20! (factorial, not excitement) :) It's frustrating because I have the Python right, but I'm getting stuck on the math. The problem: "What is the

Re: Using django ORM from web browser and from command line apps

2011-06-21 Thread News123
On 06/22/2011 03:08 AM, Ian Kelly wrote: > On Tue, Jun 21, 2011 at 6:21 PM, News123 wrote: >> Out of curiousity: Do you know whether the imports would be executed for >> each potential command as soon as I call manage.py or only >> 'on demand'? > > Off the top of my head, I don't know. Never min

Re: using only the django ORM (DB access model) and nothing else.

2011-06-21 Thread News123
On 06/22/2011 03:02 AM, Roy Smith wrote: > In article <4e012e8d$0$23682$426a3...@news.free.fr>, > News123 wrote: > > > I don't see any reason you couldn't use the Model layer by itself, if > you want to. It pretty much stands on its own. Thanks a lot for confirming, I have now my small exam

Re: using only the django ORM (DB access model) and nothing else.

2011-06-21 Thread News123
On 06/22/2011 03:04 AM, Ian Kelly wrote: >> >> So I need at least a little more to make my script work. > > There's a bit of magic in the way Django finds things, and I think > you'll still need to keep the basic structure of a Django project -- > models should be in a "models.py" file located in

Re: using only the django ORM (DB access model) and nothing else.

2011-06-21 Thread News123
It seems I found a solution (refer to end of this tessage). Not sure though if there are any drawbacks or if this method of working could cause any other issues. On 06/22/2011 02:42 AM, News123 wrote: > On 06/22/2011 01:51 AM, News123 wrote: >> Hi, >> >> I have a small application running on a

Re: Using django ORM from web browser and from command line apps

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 6:21 PM, News123 wrote: > Out of curiousity: Do you know whether the imports would be executed for > each potential command as soon as I call manage.py or only > 'on demand'? Off the top of my head, I don't know. -- http://mail.python.org/mailman/listinfo/python-list

Re: using only the django ORM (DB access model) and nothing else.

2011-06-21 Thread Roy Smith
In article <4e012e8d$0$23682$426a3...@news.free.fr>, News123 wrote: > Hi, > > I have a small application running on a host without web server and > without any need for django except its ORM accessing data bases without > explicitely writing sql queries.) You would do much better to ask this q

Re: using only the django ORM (DB access model) and nothing else.

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 6:42 PM, News123 wrote: > ### > If running myapp.py I get following output: > > yes this line is executed > Traceback (most recent call last): >  File "./myapp.py", line 11, in >    class Mini(models.Model): >  File > "/opt/my_py

Re: Is the mailing list to usenet gateway borked?

2011-06-21 Thread Ben Finney
Steven D'Aprano writes: > The last couple of messages on this list show > up fine on the mailman archives, but are empty posts on > comp.lang.python. Is there a problem with the mail -> usenet gateway? I don't see empty messages through Usenet. However, at around the time you reported this, I

Security test of embedded Python

2011-06-21 Thread Chris Angelico
I'm involved in the construction of an environment that allows end users to supply scripts which will then run on our servers. We need to be able to offer the full flexibility of a scripting language, but without the risk of compromise to our computers. To that end, we have set up a system with pre

Re: using only the django ORM (DB access model) and nothing else.

2011-06-21 Thread News123
On 06/22/2011 01:51 AM, News123 wrote: > Hi, > > I have a small application running on a host without web server and > without any need for django except its ORM accessing data bases without > explicitely writing sql queries.) > > I assume there's many libraries (SQL Alchemy or others), which cou

Re: Using django ORM from web browser and from command line apps

2011-06-21 Thread News123
Hi Ian, On 06/22/2011 02:09 AM, Ian Kelly wrote: > On Tue, Jun 21, 2011 at 5:39 PM, News123 wrote: >> I'm having a django browser application. >> >> There's certain administrative tasks, that I'd like to perform from the >> command line (cronjob or manually). > It sounds like you probably want a

Tkinter/scrollbar/canvas question

2011-06-21 Thread agb
Dear Pythonistas, I've been trying to write a script that results in a set of widgets in a scrollable widget. Since tkinter is "the" gui for Python (and about the only one that I can be sure will not require additional software installation), I went that route, and wrote the following: from tkint

Re: Using django ORM from web browser and from command line apps

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 5:39 PM, News123 wrote: > Hi, > > I'm having a django browser application. > > There's certain administrative tasks, that I'd like to perform from the > command line (cronjob or manually). > As these scripts might be huge and might consume quite some memory I'd > prefer, th

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Paul Rubin
John Salerno writes: > However, even after reading the Wikipedia page about prime numbers and > trial division, I'm still a little unclear as to why the square root > of the number is the upper bound of the range you need to check. Suppose p is the smallest divisor of n, and p > sqrt(n). ("Diviso

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Paul Rubin
Terry Reedy writes: >> efficient implementation will allow a solution to be obtained on a >> modestly powered computer in less than one minute." > If something really takes a minute in C, > allow yourself at least 10 minutes or even more with plain CPython. No. The idea of the Euler problems is

using only the django ORM (DB access model) and nothing else.

2011-06-21 Thread News123
Hi, I have a small application running on a host without web server and without any need for django except its ORM accessing data bases without explicitely writing sql queries.) I assume there's many libraries (SQL Alchemy or others), which could do this job. and which migh have less overhead tha

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Vlastimil Brom
2011/6/21 John Salerno : > However, even after reading the Wikipedia page about prime numbers and > trial division, I'm still a little unclear as to why the square root > of the number is the upper bound of the range you need to check. > -- There are likely be some more elaborated proofs, but it s

Using django ORM from web browser and from command line apps

2011-06-21 Thread News123
Hi, I'm having a django browser application. There's certain administrative tasks, that I'd like to perform from the command line (cronjob or manually). As these scripts might be huge and might consume quite some memory I'd prefer, that they were not part of the normal application and would just

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Terry Reedy
On 6/21/2011 3:48 PM, John Salerno wrote: Absolutely not! Each problem has been designed according to a "one- minute rule", which means that although it may take several hours to design a successful algorithm with more difficult problems, an efficient implementation will allow a solution to be o

Re: Finding greatest prime factor, was Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Chris Angelico
Oops, realized after posting that there's a bug in my code - it returns 1 for a perfect square. Need another check in the 'while' loop, thus: On Wed, Jun 22, 2011 at 8:59 AM, Chris Angelico wrote: > exec 600851475143; for (int i=2;ii) ret/=i > >  while not ret%i and ret>i: Definitely room for im

Re: new string-formatting preferred? (was "What is this syntax ?")

2011-06-21 Thread Tim Chase
On 06/21/2011 05:19 PM, Terry Reedy wrote: On 6/21/2011 7:33 AM, Tim Chase wrote: http://docs.python.org/library/stdtypes.html#str.format> Is there a good link to a thread-archive on when/why/how .format(...) became "preferred to the % formatting"? That is a controversial statement. I'm no

Finding greatest prime factor, was Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Chris Angelico
On Wed, Jun 22, 2011 at 7:48 AM, John Salerno wrote: > Thanks for the all the advice everyone. Now I'm on to problem #4, and > I'm stumped again, but that's what's fun! :) So now that you've solved it, I'd like to see some fast one-liners to do the job. (Since Python cares about whitespace, it mi

Re: something about performence

2011-06-21 Thread Terry Reedy
On 6/20/2011 10:59 PM, king6c...@gmail.com wrote: > Hi, > I have two large files,each has more than 2 lines,and each line > consists of two fields,one is the id and the other a value, > the ids are sorted. > > for example: > > file1 > (uin_a y) > 1 1245 > 2 12333 > 3 324543 > 5 34645

Re: new string-formatting preferred? (was "What is this syntax ?")

2011-06-21 Thread Terry Reedy
On 6/21/2011 7:33 AM, Tim Chase wrote: On 06/20/2011 09:17 PM, Terry Reedy wrote: On 6/20/2011 8:46 PM, Tim Chase wrote: On 06/20/2011 05:19 PM, Ben Finney wrote: “This method of string formatting is the new standard in Python 3.0, and should be preferred to the % formatting described in Strin

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
On Jun 21, 4:41 pm, Ian Kelly wrote: > On Tue, Jun 21, 2011 at 3:09 PM, John Salerno wrote: > > Don't worry, I was still unclear about what to do after reading all > > the responses, even yours! But one thing that made me feel better was > > that I wasn't having a Python problem as much as a *mat

Re: those darn exceptions

2011-06-21 Thread Chris Torek
>On Tue, 21 Jun 2011 01:43:39 +, Chris Torek wrote: >> But how can I know a priori >> that os.kill() could raise OverflowError in the first place? In article <4e006912$0$29982$c3e8da3$54964...@news.astraweb.com> Steven D'Aprano wrote: >You can't. Even if you studied the source code, you coul

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 3:09 PM, John Salerno wrote: > Don't worry, I was still unclear about what to do after reading all > the responses, even yours! But one thing that made me feel better was > that I wasn't having a Python problem as much as a *math* problem. I > changed my get_factors functio

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Irmen de Jong
On 21-6-2011 23:09, John Salerno wrote: > On Jun 21, 3:22 pm, Irmen de Jong wrote: >> On 21-06-11 22:10, Irmen de Jong wrote: >> [stuff] >> >> I didn't read the last paragraph of John's message until just now, and >> now realize that what I wrote is likely way too much information for >> what he a

Re: Handling import errors

2011-06-21 Thread Mel
Guillaume Martel-Genest wrote: > What is the pythonic way to handle imports error? What is bugging me > is that the imports can't be inside a function (because I use them in > different places in the script and thus they have to be in the global > scope). Actually, you can if you declare them glo

Re: Handling import errors

2011-06-21 Thread Miki Tebeka
> try: > import foo > except ImportError: > logging.error('could not import foo') > sys.exit(1) Why not just let the exception terminate the program? It will have even more information about the problem that caused foo not to load. -- http://mail.python.org/mailman/listinfo/python-lis

Re: Handling import errors

2011-06-21 Thread Tim Johnson
* Guillaume Martel-Genest [110621 12:53]: > What is the pythonic way to handle imports error? What is bugging me > is that the imports can't be inside a function (because I use them in > different places in the script and thus they have to be in the global > scope). I would write something like:

Re: sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
On Jun 21, 3:22 pm, Irmen de Jong wrote: > On 21-06-11 22:10, Irmen de Jong wrote: > [stuff] > > I didn't read the last paragraph of John's message until just now, and > now realize that what I wrote is likely way too much information for > what he asked. > I'm sorry. Next time I'll read everythin

Handling import errors

2011-06-21 Thread Guillaume Martel-Genest
What is the pythonic way to handle imports error? What is bugging me is that the imports can't be inside a function (because I use them in different places in the script and thus they have to be in the global scope). I would write something like: try: import foo except ImportError: logging

Handling import errors

2011-06-21 Thread Guillaume Martel-Genest
What is the pythonic way to handle imports error? What is bugging me is that the imports can't be inside a function (because I use them in different places in the script and thus they have to be in the global scope). I would write something like: try: -- http://mail.python.org/mailman/listinfo/py

Re: running an existing script

2011-06-21 Thread Adam Chapman
On Jun 21, 8:00 pm, Ethan Furman wrote: > Adam Chapman wrote: > > Thanks Ethan > > > No way could I have worked that out in my state of stress! > > > For your second idea, would I need to type that into the python command > > line interface (the one that looks like a DOS window? > > If you are act

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread MRAB
On 21/06/2011 20:48, John Salerno wrote: I'm working on the Project Euler exercises and I'm stumped on problem 3: "What is the largest prime factor of the number 600851475143 ?" Now, I've actually written functions to get a list of the factors of any given number, and then another function to g

sorry, possibly too much info. was: Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Irmen de Jong
On 21-06-11 22:10, Irmen de Jong wrote: [stuff] I didn't read the last paragraph of John's message until just now, and now realize that what I wrote is likely way too much information for what he asked. I'm sorry. Next time I'll read everything until and including the last full stop. Irmen -

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Mel
John Salerno wrote: > I'm working on the Project Euler exercises and I'm stumped on problem > 3: > > "What is the largest prime factor of the number 600851475143 ?" [ ... ] > Here is what I have so far. Initially the get_factors function just > iterated over the entire range(2, n + 1), but since a

Re: How to get return values of a forked process

2011-06-21 Thread Chris Torek
>> On Tue, Jun 21, 2011 at 12:26 PM, Ian wrote: >>> myForkedScript has code like this: >>> if fail: >>> os._exit(1) >>> else: >>>os._exit(os.EX_OK) >>> >>> Is using os._exit() the correct way to get a return value back to the >>> main process? "The" correct way, no, but it is "a" correct

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Irmen de Jong
On 21-06-11 21:48, John Salerno wrote: I'm working on the Project Euler exercises and I'm stumped on problem 3: "What is the largest prime factor of the number 600851475143 ?" Now, I've actually written functions to get a list of the factors of any given number, and then another function to get

Re: basic bytecode to machine code compiler (part 3)

2011-06-21 Thread Rouslan Korneychuk
On 06/21/2011 06:55 AM, Ulrich Eckhardt wrote: Rouslan Korneychuk wrote: if i != pindex: (less if x<= pivot else greater).append(x) Just curious, is there a reason why you wrote this last line that way instead of using a "normal" if/else clause? Cheers! Uli No special reason. I jus

Re: How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 1:48 PM, John Salerno wrote: > Here is what I have so far. Initially the get_factors function just > iterated over the entire range(2, n + 1), but since a number can't > have a factor greater than half of itself, I tried to shorten the > range by doing range(2, n //2), but

How can I speed up a script that iterates over a large range (600 billion)?

2011-06-21 Thread John Salerno
I'm working on the Project Euler exercises and I'm stumped on problem 3: "What is the largest prime factor of the number 600851475143 ?" Now, I've actually written functions to get a list of the factors of any given number, and then another function to get the prime numbers from that list. It wor

Re: How to get return values of a forked process

2011-06-21 Thread Ian Kelly
> Where did you find the Unix docs you pasted in?  I didn't find it in > the man pages.  Thank you.  Based on what you say, I will change my > os._exit() to sys.exit(). http://docs.python.org/library/os.html#os.wait http://docs.python.org/library/os.html#os.waitpid I don't know what man pages you

Re: How to get return values of a forked process

2011-06-21 Thread Miki Tebeka
One way is to use pipes, have a look at http://code.activestate.com/recipes/576709/ for example. -- http://mail.python.org/mailman/listinfo/python-list

Re: parse date string having "EDT"

2011-06-21 Thread Miki Tebeka
You might consider trying dateutil.parser.parse (http://labix.org/python-dateutil#head-c0e81a473b647dfa787dc11e8c69557ec2c3ecd2) -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get return values of a forked process

2011-06-21 Thread Ian
On Jun 21, 1:54 pm, Ian Kelly wrote: > On Tue, Jun 21, 2011 at 12:26 PM, Ian wrote: > > myForkedScript has code like this: > > if fail: > >    os._exit(1) > > else: > >    os._exit(os.EX_OK) > > > Is using os._exit() the correct way to get a return value back to the > > main process? > > sys.exit

Re: Don't understand SequenceMatcher from difflib

2011-06-21 Thread Terry Reedy
On 6/21/2011 9:43 AM, Antoon Pardon wrote: matcher = SequenceMatcher(ls1, ls2) ... What am I doing wrong? Read the doc, in particular, the really stupid signature of the class: "class difflib.SequenceMatcher(isjunk=None, a='', b='', autojunk=True)" You are passing isjunk = ls1, a = ls2,

Re: How to get return values of a forked process

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 12:26 PM, Ian wrote: > myForkedScript has code like this: > if fail: >os._exit(1) > else: >os._exit(os.EX_OK) > > Is using os._exit() the correct way to get a return value back to the > main process? sys.exit() is the preferred way. > I thought the value 'n', pass

Re: running an existing script

2011-06-21 Thread Ethan Furman
Adam Chapman wrote: Thanks Ethan No way could I have worked that out in my state of stress! For your second idea, would I need to type that into the python command line interface (the one that looks like a DOS window? If you are actually in a python CLI, at the top of that screen does it sa

Simple question about loading a .glade UI file

2011-06-21 Thread Anthony Papillion
Hi Everyone, So I'm tackling designing a non-CLI program using Glade. I went through some tutorials and it seems like I'm doing things right but I'm my UI won't load. Python keeps griping about "could not create glade XML object". I have a .glade file called MainWindow.glade and my main window is

How to get return values of a forked process

2011-06-21 Thread Ian
Hello all, I need some helped with forking. In my script, I fork a process. I want to get return values from the child process. This is the script that does the forking: for x in (mylist): pid = os.fork() if pid: pidList.append(pid) else: os.execv('/usr/bin/python',('/

Re: running an existing script

2011-06-21 Thread Benjamin Kaplan
On Tue, Jun 21, 2011 at 10:45 AM, Adam Chapman wrote: > Hi, > > I'm trying to put together a lot of pieces of source code in matlab, > java, perl and python. > > Im an expert when it comes to matlab, but novice in all the others > listed above. However, I have integrated the java and perl code so

Re: Better way to iterate over indices?

2011-06-21 Thread Ethan Furman
Billy Mays wrote: I have always found that iterating over the indices of a list/tuple is not very clean: for i in range(len(myList)): doStuff(i, myList[i]) Definitely not beautiful. ;) I know I could use enumerate: for i, v in enumerate(myList): doStuff(i, myList[i]) If you actu

Re: Better way to iterate over indices?

2011-06-21 Thread Benjamin Kaplan
On Tue, Jun 21, 2011 at 11:05 AM, Billy Mays wrote: > I have always found that iterating over the indices of a list/tuple is not > very clean: > > for i in range(len(myList)): >    doStuff(i, myList[i]) > > > > > I know I could use enumerate: > > for i, v in enumerate(myList): >    doStuff(i, myLi

Re: Better way to iterate over indices?

2011-06-21 Thread Noah Hall
On Tue, Jun 21, 2011 at 7:05 PM, Billy Mays wrote: > I have always found that iterating over the indices of a list/tuple is not > very clean: > > for i in range(len(myList)): >    doStuff(i, myList[i]) > I know I could use enumerate: > > for i, v in enumerate(myList): >    doStuff(i, myList[i]) >

Re: running an existing script

2011-06-21 Thread Ethan Furman
Adam Chapman wrote: Hi, Howdy! I'm trying to put together a lot of pieces of source code in matlab, java, perl and python. [snippety] Basically I just want to run a single script from the python command window. Once I know how to do that I can be off on my way to perform the matlab interf

Re: Better way to iterate over indices?

2011-06-21 Thread Ian Kelly
On Tue, Jun 21, 2011 at 12:05 PM, Billy Mays wrote: > I know I could use enumerate: > > for i, v in enumerate(myList): >    doStuff(i, myList[i]) > > ...but that stiff seems clunky. Why not: for i, v in enumerate(myList): doStuff(i, v) -- http://mail.python.org/mailman/listinfo/python-list

Re: parse date string having "EDT"

2011-06-21 Thread Junaid P V
Thanks, My script should be platform independent, so I think filtering out time zone info is better. -- http://mail.python.org/mailman/listinfo/python-list

Better way to iterate over indices?

2011-06-21 Thread Billy Mays
I have always found that iterating over the indices of a list/tuple is not very clean: for i in range(len(myList)): doStuff(i, myList[i]) I know I could use enumerate: for i, v in enumerate(myList): doStuff(i, myList[i]) ...but that stiff seems clunky. Are there any better ways to

running an existing script

2011-06-21 Thread Adam Chapman
Hi, I'm trying to put together a lot of pieces of source code in matlab, java, perl and python. Im an expert when it comes to matlab, but novice in all the others listed above. However, I have integrated the java and perl code so they can be called from matlab. I know that there is a toolbox out

Re: Do we still need to inherit from "object" to create new-style classes?

2011-06-21 Thread Terry Reedy
On 6/20/2011 9:26 PM, John Salerno wrote: I can't quite seem to find the answer to this anywhere. The book I'm reading right now was written for Python 3.1 and doesn't use (object), so I'm thinking that was just a way to force new-style classes in 2.x and is no longer necessary in 3.x. Is that ri

Re: Is the mailing list to usenet gateway borked?

2011-06-21 Thread Peter Pearson
On 20 Jun 2011 23:49:11 GMT, Steven D'Aprano wrote: [snip] > I will treat this as a bug in Pan, and take it to the appropriate forums, > but for anyone who cares, here's one example: > > From: Steven D'Aprano > Subject: Re: What is this syntax ? > Newsgroups: comp.lang.python > References:

Re: Rant on web browsers

2011-06-21 Thread ron_m
This might help http://blog.stevenlevithan.com/archives/date-time-format -- http://mail.python.org/mailman/listinfo/python-list

[OT] One click, one (buggy) life...

2011-06-21 Thread DavCori80
Hi everyone, I would like to share a youtube clip...one click costs nothing while can save lives sometimes (especially mine). http://www.youtube.com/watch?v=PiCeqtGHpJI Thanks a lot and cheers. DavCori http://www.ar4tro.com/welcome.html -- http://mail.python.org/mailman/listinfo/python-list

[ANN] Shed Skin 0.8

2011-06-21 Thread Mark Dufour
Hi all, I have just released version 0.8 of Shed Skin, an experimental (restricted-)Python-to-C++ compiler. Please see my blog for the full announcement: http://shed-skin.blogspot.com The Shed Skin homepage can be found here: http://shedskin.googlecode.com Thanks, Mark Dufour -- http://www.

Re: How to iterate on a changing dictionary

2011-06-21 Thread MRAB
On 21/06/2011 12:51, Gurpreet Singh wrote: Perhaps this is the simplest and best solution which appears in this case. Just copy the desired items to a new dictionary and discard the original one. import re myDict={'a':'alpha','b':'beta','c':'charley','d':'disney'} myNewDict={} for k,v in myDict

Don't understand SequenceMatcher from difflib

2011-06-21 Thread Antoon Pardon
I have the following code I wrote. == from difflib import SequenceMatcher import sys write = sys.stdout.write warn = sys.stderr.write def program(argv): ls1 = open(argv[1]).readlines() ls2 = open(argv[2]).readlines() matcher = SequenceMatcher(l

Emails backup in python 3.2

2011-06-21 Thread TheSaint
Hello, I'm looking for an idea how to backup emails retrieved by poplib and save them into mailbox.mbox file. The problem is the received message which is a list of bytes streams, mailbox.mbox don't expect a list. What conversion should I do? A file type io.StringIO ? decoding every bytes stream

Web design services | website designing | hire a website designer | creative web design

2011-06-21 Thread sravan kumar
web design services, XHTML Conversion Services, Offshore outsourcing web design & SEO Expert Acedezines provides best services for your website design, search engine optimization, web design services, brochure design, flash intro animation, website designing, wordpress themes. for more details http

Re: break in a module

2011-06-21 Thread Cameron Simpson
On 21Jun2011 20:04, I wrote: | So the caller does an: | | import foo | | as normal, with no special wrapping. And the module goes: | | spam() | if condition: | raise StopIteration | ham() | cheese() Of course, that should be StopImport, not StopIteration. Cheers, -- Cameron Simp

PSD to XHTML Conversion Services and PSD to HTML CSS Conversion Services, PSD to Joomla, Drupal, Wordpress Conversion

2011-06-21 Thread xhtml champs
PSD to XHTML Conversion, PSD to HTML CSS, Joomla, Wordpress, Drupal, CMS, VBULLETIN, PHPBB and includes convert to XHTML like PSD to XHTML, web designing services, logos and banner design, website building, animation,presentations. for more details: http://www.xhtmlchamps.com -- http://mail.pytho

Re: How to iterate on a changing dictionary

2011-06-21 Thread Gurpreet Singh
Perhaps this is the simplest and best solution which appears in this case. Just copy the desired items to a new dictionary and discard the original one. import re myDict={'a':'alpha','b':'beta','c':'charley','d':'disney'} myNewDict={} for k,v in myDict.iteritems(): if re.search("a",v)!=None:

  1   2   >