[Tutor] (no subject)

2010-11-09 Thread First Ramses
-- mzperx ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] List comprehension question

2010-11-09 Thread Richard D. Moores
On Mon, Nov 8, 2010 at 23:49, Richard D. Moores wrote: > On Mon, Nov 8, 2010 at 22:47, Richard D. Moores wrote: >> On Mon, Nov 8, 2010 at 21:31, Richard D. Moores wrote: >> >>> That sqrt(n) works for speeding up the finding of primes, but here we >>> want to use int(n/2) (and why didn't I think

[Tutor] Need help with script for finding pairs of amicable numbers

2010-11-09 Thread Richard D. Moores
Here's what I have so far: . My immediate question is, is there a general way to determine the multiplier of n in line 44? Of course, by trial and error I can find out pretty exactly what it should be to find a pair that I know of. But of course I want to go o

Re: [Tutor] How to copy file from a source, I do not know the source file name, Only path to the src directory I know

2010-11-09 Thread Evert Rol
> Hi All > I am trying our "Python" . > My aim is to copy a file to a location and later removing the > file.I had written a small script which works.It works only if I > specify the source file name. I would like to make it work in a > scenario in which I do not know the name of the source fil

Re: [Tutor] List comprehension question

2010-11-09 Thread Stefan Behnel
Richard D. Moores, 09.11.2010 12:07: That sqrt(n) works for speeding up the finding of primes, but here we want to use int(n/2) (and why didn't I think of that?), which results in about a 2x speedup. See. NO! Use int(n/2)+1 . I'll correct that in

[Tutor] How to copy file from a source, I do not know the source file name, Only path to the src directory I know

2010-11-09 Thread Joseph John
Hi All I am trying our "Python" . My aim is to copy a file to a location and later removing the file.I had written a small script which works.It works only if I specify the source file name. I would like to make it work in a scenario in which I do not know the name of the source file(the sour

Re: [Tutor] How to copy file from a source, I do not know the source file name, Only path to the src directory I know

2010-11-09 Thread Joel Goldstick
On Tue, Nov 9, 2010 at 7:15 AM, Joseph John wrote: > Hi All > I am trying our "Python" . > My aim is to copy a file to a location and later removing the > file.I had written a small script which works.It works only if I > specify the source file name. I would like to make it work in a > scena

Re: [Tutor] How to copy file from a source, I do not know the source file name, Only path to the src directory I know

2010-11-09 Thread Evert Rol
> I was able to solve it > by > " > dirList=os.listdir(src) > for fname in dirList: > print fname > ffname = '/home/joseph/Projects/Training/Python/example/One/'+fname tip: use os.path.join for concatenating paths. It's smart, and (in principle) OS-agnostic. Also, if you use 'os.list

Re: [Tutor] List comprehension question

2010-11-09 Thread Richard D. Moores
On Tue, Nov 9, 2010 at 03:35, Stefan Behnel wrote: > Richard D. Moores, 09.11.2010 12:07: > > That sqrt(n) works for speeding up the finding of primes, but here we > want to use int(n/2) (and why didn't I think of that?), which results > in about a 2x speedup. See

Re: [Tutor] How to copy file from a source, I do not know the source file name, Only path to the src directory I know

2010-11-09 Thread Joseph John
Thanks I was able to solve it by " dirList=os.listdir(src) for fname in dirList: print fname ffname = '/home/joseph/Projects/Training/Python/example/One/'+fname print ffname #shutil.copy(ffname,dst2) shutil.move(ffname,dst3) " On Tue, Nov 9, 2010 at 4:38 P

Re: [Tutor] List comprehension question

2010-11-09 Thread Martin A. Brown
Hello, : def proper_divisors_sum(n): : pd_list = [] : for x in range(1, int(n**.5)+1): : if n % x == 0: : factor = int(x) : pd_list.append(factor) : factor2 = int(n/factor) : pd_list.append(factor2) : pd_list = list(set(

Re: [Tutor] List comprehension question

2010-11-09 Thread Richard D. Moores
On Tue, Nov 9, 2010 at 05:51, Martin A. Brown wrote: > > Hello, > >  : def proper_divisors_sum(n): >  :     pd_list = [] >  :     for x in range(1, int(n**.5)+1): >  :         if n % x == 0: >  :             factor = int(x) >  :             pd_list.append(factor) >  :             factor2 = int(n/f

Re: [Tutor] Too different 2.6 vs 2.7?

2010-11-09 Thread Mac Ryan
On Mon, 2010-11-08 at 17:16 -0800, Terry Carroll wrote: > The only feature I'm pining for at all is the new argparse; but it > depends on your needs. Ubuntu 10.10 here (running python 2.6.6) I use argparse without any problems: I believe the difference between 2.6 and 2.7 [I am not an expert

Re: [Tutor] query result set

2010-11-09 Thread bob gailer
When starting a new subject, please start with a new email. Do not "hijack" an existing one, as that causes your query to appear as part of the hijacked thread. -- Bob Gailer 919-636-4239 Chapel Hill NC ___ Tutor maillist - Tutor@python.org To uns

Re: [Tutor] Columnar Transposition Cipher question

2010-11-09 Thread Stefan Behnel
Steven D'Aprano, 09.11.2010 05:01: http://pypi.python.org/pypi/obfuscate Hmm - why is the Windows installer on that page called "linux-i686"? Stefan ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.p

Re: [Tutor] Columnar Transposition Cipher question

2010-11-09 Thread Eike Welk
On Tuesday 09.11.2010 18:36:43 Stefan Behnel wrote: > Steven D'Aprano, 09.11.2010 05:01: > > http://pypi.python.org/pypi/obfuscate > > Hmm - why is the Windows installer on that page called "linux-i686"? It was probably created on Linux. Python's Distutils create installers for Windows even on L

Re: [Tutor] List comprehension question

2010-11-09 Thread Steven D'Aprano
Richard D. Moores wrote: See for a speed test with n = 100,000 and 100,000 loops As a general rule, you shouldn't try to roll your own speed tests. There are various subtleties that can throw your results right out. Timing small code snippets on modern

Re: [Tutor] Columnar Transposition Cipher question

2010-11-09 Thread Steven D'Aprano
Eike Welk wrote: On Tuesday 09.11.2010 18:36:43 Stefan Behnel wrote: Steven D'Aprano, 09.11.2010 05:01: http://pypi.python.org/pypi/obfuscate Hmm - why is the Windows installer on that page called "linux-i686"? It was probably created on Linux. That would be it. > Python's Distutils crea

Re: [Tutor] List comprehension question

2010-11-09 Thread Albert-Jan Roskam
For larger blocks of code, cProfile may also be useful for speed tests. Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and

Re: [Tutor] List comprehension question

2010-11-09 Thread Richard D. Moores
On Tue, Nov 9, 2010 at 12:54, Steven D'Aprano wrote: > Richard D. Moores wrote: > >> See for a speed test with n = >> 100,000 and 100,000 loops > > As a general rule, you shouldn't try to roll your own speed tests. There are > various subtleties that can thr

Re: [Tutor] List comprehension question

2010-11-09 Thread Alan Gauld
"Richard D. Moores" wrote Question: When I dump in more that one line of any code (properly indented), after running it once, I've never known how to run it again without a redump. The up arrow just gets me one line at a time. So, how to do it? It depends on your IDE. On IDLE I think its

Re: [Tutor] Columnar Transposition Cipher question

2010-11-09 Thread Emile van Sebille
On 11/9/2010 1:29 PM Steven D'Aprano said... I'm pretty sure I tried it, once, but I might be confabulating. Cool -- I learned a new word today! I had to look it up as I thought you were profabulating... :) Emile ___ Tutor maillist - Tutor@pyth

Re: [Tutor] List comprehension question

2010-11-09 Thread C or L Smith
>> 1. Re: List comprehension question (Richard D. Moores) >>> ?: def proper_divisors_sum(n): >>> A few questions--noting, of course, that I'm not reading this with >>> an eye toward performance, which it seems you are, but these occur >>> to me: Tim Peters had a beautiful little version of divi

Re: [Tutor] List comprehension question

2010-11-09 Thread Richard D. Moores
On Tue, Nov 9, 2010 at 18:29, C or L Smith wrote: > >From sympy you simply do: > from sympy import divisors list(divisors(256)) > [1, 2, 4, 8, 16, 32, 64, 128, 256] > > So your proper divisors would just be sum(divisors(n)) - n. > The divisors function there is in the ntheory/factor_.py

Re: [Tutor] List comprehension question

2010-11-09 Thread Stefan Behnel
Richard D. Moores, 10.11.2010 08:24: def proper_divisors_sum(n): pd = set((1,)) for x in range(2, int(n**.5)+1): if n % x == 0: pd.update((x, n//x)) return sum(list(pd)) You keep using redundant operations. What "sum(list(s))" does, for s being a set, is: