Re: [Tutor] Generate Prime Numbers

2015-05-29 Thread Stefan Behnel
Mirage Web Studio schrieb am 29.05.2015 um 17:28: > Below is a sample code i created. > Can i better it any way? Absolutely. Prime number generation is a very well researched and fun to implement topic. Thus many people have done it before. See this for algorithmic improvements: https://pypi.pyt

Re: [Tutor] Generate Prime Numbers

2015-05-29 Thread Cameron Simpson
On 29May2015 18:48, alan.ga...@btinternet.com wrote: On 29/05/15 16:28, Mirage Web Studio wrote: def IsDivisibleBy3(number):#string variable v=0 for c in number: v=v+int(c) if v%3==0: return True else: return False def IsDivisibleBy3(number):#string var

Re: [Tutor] Directories and Macintosh

2015-05-29 Thread Alan Gauld
On 29/05/15 18:10, Barth, Dylan wrote: Hi there, I've never used this before and I'm very new to programming, Welcome. I want to change my working directory in python > (permanently if at all possible) What exactly do you mean by your working directory? And "permanently" is a very long time

Re: [Tutor] Directories and Macintosh

2015-05-29 Thread Steven D'Aprano
Hi Dylan, and welcome! On Fri, May 29, 2015 at 05:10:33PM +, Barth, Dylan wrote: > Hi there, I've never used this before and I'm very new to programming, > but I have an interesting and unique problem. I want to change my > working directory in python (permanently if at all possible) "Wo

Re: [Tutor] Generate Prime Numbers

2015-05-29 Thread Alan Gauld
On 29/05/15 16:28, Mirage Web Studio wrote: Below is a sample code i created. Can i better it any way? Of course. There is always improvements that can be made. But in your case there are quite a few! def IsDivisibleBy3(number):#string variable v=0 for c in number: v=v+in

[Tutor] Directories and Macintosh

2015-05-29 Thread Barth, Dylan
Hi there, I've never used this before and I'm very new to programming, but I have an interesting and unique problem. I want to change my working directory in python (permanently if at all possible) and nothing I can find online works, even when I've copy/pasted it into python. I downloaded the a

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Laura Creighton
In a message of Fri, 29 May 2015 14:13:16 +0100, Oscar Benjamin writes: >Python 2.7.2 (1.8+dfsg-2, Feb 19 2012, 19:18:08) >[PyPy 1.8.0 with GCC 4.6.2] > >$ pypy gencm.py >Entering >End of program > >The __exit__ method was not called at all under pypy. Even if I don't >keep a reference to g outsid

[Tutor] Generate Prime Numbers

2015-05-29 Thread Mirage Web Studio
Hello, Below is a sample code i created. Can i better it any way? Thanks George --- import time start_time = time.time() def IsDivisibleBy3(number):#string variable v=0 for c in number: v=v+int(c) if v%3==0:

Re: [Tutor] inserting path to open a file from a variable

2015-05-29 Thread Brandon McCaig
Richard: On Thu, May 28, 2015 at 1:39 PM, richard kappler wrote: > # line two is the absolute path to the log you are parsing data from > # keep 'rdfile:' as is, path starts after it, no spaces > rdfile:Documents/MyScripts/fileMonitor/log.txt > # line 4 is the absolute path to the log you are app

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Mark Lawrence
On 29/05/2015 15:23, Steven D'Aprano wrote: On Thu, May 28, 2015 at 10:16:00AM +0200, Peter Otten wrote: As interesting as this may be does it really belong on the tutor mailing list? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language.

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Steven D'Aprano
On Fri, May 29, 2015 at 03:01:50PM +0100, Oscar Benjamin wrote: > On 29 May 2015 at 14:29, Steven D'Aprano wrote: > > On Thu, May 28, 2015 at 10:16:00AM +0200, Peter Otten wrote: > > > >> Even if you limit yourself to CPython there is another effect: the order of > >> execution may not meet one's

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Steven D'Aprano
On Thu, May 28, 2015 at 10:16:00AM +0200, Peter Otten wrote: > Even if you limit yourself to CPython there is another effect: the order of > execution may not meet one's expectations/requirements: No, wait, forget everything I said in my previous post. This is *clearly* a case where our expecta

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Oscar Benjamin
On 29 May 2015 at 14:29, Steven D'Aprano wrote: > On Thu, May 28, 2015 at 10:16:00AM +0200, Peter Otten wrote: > >> Even if you limit yourself to CPython there is another effect: the order of >> execution may not meet one's expectations/requirements: > > [snip example] > > That's an interesting ex

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Steven D'Aprano
I have to think further on most of your post, but for the last point: On Fri, May 29, 2015 at 02:13:16PM +0100, Oscar Benjamin wrote: > Now run the same under pypy: > > $ pypy --version > Python 2.7.2 (1.8+dfsg-2, Feb 19 2012, 19:18:08) > [PyPy 1.8.0 with GCC 4.6.2] > > $ pypy gencm.py > Enteri

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Steven D'Aprano
On Thu, May 28, 2015 at 10:16:00AM +0200, Peter Otten wrote: > Even if you limit yourself to CPython there is another effect: the order of > execution may not meet one's expectations/requirements: [snip example] That's an interesting example, and I can't tell if that's a problem with your (and

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Oscar Benjamin
On 29 May 2015 at 13:38, Steven D'Aprano wrote: > > Otherwise I stand by my earlier position that you are misinterpreting > what it means to exit a with block. Pausing it to yield is not an exit. > > I did an experiment, where I tried to break the finalisation > guarantee using break, return and r

Re: [Tutor] Yielding from a with block

2015-05-29 Thread Steven D'Aprano
On Thu, May 28, 2015 at 10:46:26AM +0100, Oscar Benjamin wrote: > I'm sure you understand the fundamental difference between calling a > function and yielding inside a with statement: when calling a function > the new frame is *appended* to the call stack keeping the current > frame and all of its