Re: [Tutor] Advice for my function, isPrime(n), please

2008-07-18 Thread Kent Johnson
On Fri, Jul 18, 2008 at 4:45 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > At 12:38 PM 7/18/2008, Kent Johnson wrote: >> >> On Fri, Jul 18, 2008 at 2:25 PM, Dick Moores <[EMAIL PROTECTED]> wrote: >> > At 10:03 AM 7/18/2008, Kent Johnson wrote: >> >> >> >> On Fri, Jul 18, 2008 at 11:32 AM, Dick Moore

Re: [Tutor] IPython problem: Difficulty in setting editor to TextPad

2008-07-18 Thread Dick Moores
At 03:41 PM 7/18/2008, arsyed wrote: I just set the EDITOR environment variable under windows to textpad and %ed works fine from ipython. It also gets used by subversion and other programs for commit messages, etc. >echo %EDITOR% "C:\Program Files\TextPad 5\TextPad.exe" I'd already done tha

Re: [Tutor] IPython problem: Difficulty in setting editor to TextPad

2008-07-18 Thread arsyed
I just set the EDITOR environment variable under windows to textpad and %ed works fine from ipython. It also gets used by subversion and other programs for commit messages, etc. >echo %EDITOR% "C:\Program Files\TextPad 5\TextPad.exe" On Thu, Jul 17, 2008 at 11:39 AM, Dick Moores <[EMAIL PROTE

Re: [Tutor] confusing HTTP error while using urlopen

2008-07-18 Thread arsyed
It looks like the site wants an Accept header. The following works: import urllib2 url = 'http://www.anuntul.ro/' headers = {'Accept': 'text/html'} req = urllib2.Request(url=url, headers=headers) rsp = urllib2.urlopen(req) page = rsp.read() print page On Fri, Jul 18, 2008 at 5:38 PM, Chad Cra

Re: [Tutor] confusing HTTP error while using urlopen

2008-07-18 Thread Chad Crabtree
Well I can confirm this behavior. I tried changing the user-agent thinking there might be some filtering based on that but no go. Still HTTP 400 error. WGET works just fine though On Fri, Jul 18, 2008 at 4:31 PM, asdg asdg <[EMAIL PROTECTED]> wrote: > I'll skip the introduction and go right to t

Re: [Tutor] Advice for my function, isPrime(n), please

2008-07-18 Thread Dick Moores
At 12:38 PM 7/18/2008, Kent Johnson wrote: On Fri, Jul 18, 2008 at 2:25 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > At 10:03 AM 7/18/2008, Kent Johnson wrote: >> >> On Fri, Jul 18, 2008 at 11:32 AM, Dick Moores <[EMAIL PROTECTED]> wrote: >> >if x == 0: >> >return False >> >else:

[Tutor] confusing HTTP error while using urlopen

2008-07-18 Thread asdg asdg
I'll skip the introduction and go right to the question cause it's as simple as it's confusing for me. Why does urllib2.urlopen("http://www.anuntul.ro";) return HTTPError: HTTP Error 400: Bad Request, while the site opens with no problems in any regular browser. Thank you in advance for answeri

Re: [Tutor] Advice for my function, isPrime(n), please

2008-07-18 Thread Kent Johnson
On Fri, Jul 18, 2008 at 2:25 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > At 10:03 AM 7/18/2008, Kent Johnson wrote: >> >> On Fri, Jul 18, 2008 at 11:32 AM, Dick Moores <[EMAIL PROTECTED]> wrote: >> >if x == 0: >> >return False >> >else: >> >return True >> >> Could be just >

Re: [Tutor] Advice for my function, isPrime(n), please

2008-07-18 Thread Dick Moores
At 10:03 AM 7/18/2008, Kent Johnson wrote: On Fri, Jul 18, 2008 at 11:32 AM, Dick Moores <[EMAIL PROTECTED]> wrote: >if x == 0: >return False >else: >return True Could be just return x!=0 I see this works, but it's Greek to me. HOW does it work? And why is it better

Re: [Tutor] parsing sendmail logs

2008-07-18 Thread Jeff Younker
If you run a pipeline chain from within subprocess every part of the chain will be a separate process, thats a lot of overhead. Thats why admins tend to prefer writing utilities in Perl rather than bash these days. ... Nobody I know uses perl for systems administration because it doesn't have

Re: [Tutor] Advice for my function, isPrime(n), please

2008-07-18 Thread Kent Johnson
On Fri, Jul 18, 2008 at 11:32 AM, Dick Moores <[EMAIL PROTECTED]> wrote: >if x == 0: >return False >else: >return True Could be just return x!=0 or return not x > My question is about whether to test for integerhood. Without that test, > isPrime(3.7) returns true, and

[Tutor] Advice for my function, isPrime(n), please

2008-07-18 Thread Dick Moores
I'm rather please with the speed of isPrime(). Any credit, of course, goes to Alex Martelli, who wrote gmpy. from gmpy import is_prime def isPrime(n): """ Return True if n is prime, False if not prime. If n not an int or a long, return None. """ if not isinstance(n, (int, long

Re: [Tutor] Question on how to do something.

2008-07-18 Thread Jerry Hill
On Thu, Jul 17, 2008 at 6:39 PM, Mitchell Nguyen <[EMAIL PROTECTED]> wrote: > Hello. I'm new to Python and I was wondering how to read all the files in a > folder. I used this program or command for single files. > > And if possible, is there a way to make it so that it waits at the end of > each f

Re: [Tutor] Guidance on jump-starting to learn Python

2008-07-18 Thread Michiel Overtoom
Setve wrote... > I have the challenge / opportunity to learn Python quickly. I > am technically-minded, but I am not a programmer. You have seen the page http://wiki.python.org/moin/BeginnersGuide, and more specific, http://wiki.python.org/moin/BeginnersGuide/NonProgrammers ? Ans of course, you

Re: [Tutor] creating pop method for stack class

2008-07-18 Thread Martin Walsh
Christopher Spears wrote: I see what you mean. I have tested it, and I have gotten a weird result: def shorten(lst): ... lst = lst[:-1] ... lista = [1,2,3,4] shorten(lista) print lista [1, 2, 3, 4] lista = [1,2,3,4] lista = lista[:-1] print lista [1, 2, 3] Strange...why does it work o

[Tutor] python environment

2008-07-18 Thread Eric Abrahamsen
I've been looking around for a good tutorial or background info on how the Python runtime environment works, and haven't quite found what I'm looking for. I started fooling with having different versions of modules available to difference processes on a single server, which led me to virtua

Re: [Tutor] creating pop method for stack class

2008-07-18 Thread John Fouhy
On 18/07/2008, Christopher Spears <[EMAIL PROTECTED]> wrote: > I see what you mean. I have tested it, and I have gotten a weird result: > > >>> def shorten(lst): > ... lst = lst[:-1] > > ... > > >>> lista = [1,2,3,4] > >>> shorten(lista) > >>> print lista > [1, 2, 3, 4] [...] > Strange...wh