Re: [Tutor] pyce, scripts complete too fast

2009-11-16 Thread Wayne Werner
On Tue, Nov 17, 2009 at 12:51 AM, rick wrote: > I was thinking to be ultra portable, I'd put python on the pocket pc. > Now I'm back to the problem that a Windows newbie would have, the > scripts complete before I can see what happened! I can get right to the > interactive mode, or I can run a s

[Tutor] pyce, scripts complete too fast

2009-11-16 Thread rick
Perhaps the wrong list, but I'll ask anyway. So I'm in the middle of starting, yet again, to learn some programming. I have 2.6.4 and 3.1 installed on the desktop (Ubuntu 9.10), 2.6.4 installed on the netbook (UNR 9.10). I was thinking to be ultra portable, I'd put python on the pocket pc. N

Re: [Tutor] search the folder for the 2 files and extract out only the version numbers 1.0 and 2.0.

2009-11-16 Thread Timo
I find regular expressions alwys hard to get, so here is my solution: >>> import glob >>> glob.glob('C:\\Users\\blueman\\Desktop\\allFiles\\MyTest[0-9].[0-9].zip') Cheers, Timo MARCUS NG schreef: Hi all, I am really new to python and I am trying to create a script that looks at file versi

Re: [Tutor] Iterable Understanding

2009-11-16 Thread Martin Walsh
Stephen Nelson-Smith wrote: > Nope - but I can look it up. The problem I have is that the source > logs are rotated at 0400 hrs, so I need two days of logs in order to > extract 24 hrs from to 2359 (which is the requirement). At > present, I preprocess using sort, which works fine as long as

Re: [Tutor] (no subject)

2009-11-16 Thread Wayne Werner
On Mon, Nov 16, 2009 at 4:52 PM, Carlos Flores wrote: > Dear Python, > > I am trying to learn Python to experience my computer programming > knowledge. > Welcome to the wonderful world of Python - we think it's a good extension of anyone's knowledge > I am working through the online textbook

Re: [Tutor] Fwd: Help on finding the 1000th prime

2009-11-16 Thread Shashwat Anand
You'r trying naive algorithm. Finding prime is one of basic elements of maths and programming. You may look at sieve of eratosthenesand sieve of atkin On Tue, Nov 17, 2009 at 3:35 AM, wrote: > > > Ke

[Tutor] (no subject)

2009-11-16 Thread Carlos Flores
Dear Python, I am trying to learn Python to experience my computer programming knowledge. I am working through the online textbook How to Think Like A Computer Scientist. I have made it through chapters 1-5 and completed the exercises at the end. Now I am on chapter 6 and I am having a lot of tro

Re: [Tutor] search the folder for the 2 files and extract out only the version numbers 1.0 and 2.0.

2009-11-16 Thread Serdar Tumgoren
> Aim: > what is the best way to look into the allFiles directory, and only search > the folder for the 2 files myTest1.0.zip and myTest2.0.zip to extract out > only the version numbers 1.0 and 2.0. > Based on the above file-naming convention, you could get at the version numbers with a combo of st

[Tutor] search the folder for the 2 files and extract out only the version numbers 1.0 and 2.0.

2009-11-16 Thread MARCUS NG
Hi all, I am really new to python and I am trying to create a script that looks at file versions of a particular file I have 4 files in a folder. One called myTest1.0.zip, myTest2.0.zip, test3.txt and test4.zip in a directory/folder called allFiles on my desktop. so the file structure is as such

Re: [Tutor] Fwd: Help on finding the 1000th prime

2009-11-16 Thread christopher . henk
Kent Johnson wrote on 11/16/2009 04:00:02 PM: > -- Forwarded message -- > From: Ray Holt > Date: Mon, Nov 16, 2009 at 1:55 PM > Subject: RE: [Tutor] Help on finding the 1000th prime > To: Kent Johnson > > > I hit the send button before I was ready. Here is the code that doesn'

Re: [Tutor] Do you use unit testing?

2009-11-16 Thread Serdar Tumgoren
> I learned TDD with PyUnit, but since moved to using Ruby, and have > been spoilt by rspec and even cucumber.  My instincts are to write > things test first, but so far I'm not finding PyUnit easy enough to > get going. > The Dive Into Python chapter walks the process of writing/thinking through

Re: [Tutor] Do you use unit testing?

2009-11-16 Thread Jeff R. Allen
> As a discipline - work out what we want to test, write the test, watch > it fail, make it pass - I find this a very productive way to think and > work. There's an emotional aspect too. Keeping a positive aspect keeps up flow, and seeing tests go from failing to passing feels really good. Making

[Tutor] "Snack" python-newt version incompatibilities.. (anaconda kickstart)

2009-11-16 Thread Chris Mueller
Hello all. I'm working on a CentOS 5.2 kickstart interface; and have been happily using %pre --interpreter /usr/bin/python to do my management for awhile now with the snack module. My problem comes in when I am attempting to use the snack.EntryWindow function; and setting default values. T

Re: [Tutor] Do you use unit testing?

2009-11-16 Thread Stephen Nelson-Smith
Great question, I learned TDD with PyUnit, but since moved to using Ruby, and have been spoilt by rspec and even cucumber. My instincts are to write things test first, but so far I'm not finding PyUnit easy enough to get going. Once I get into the groove, I find it's a wonderful way to work - an

Re: [Tutor] A way to search archives?

2009-11-16 Thread Kent Johnson
On Mon, Nov 16, 2009 at 2:34 PM, Ray Holt wrote: > Is there a way to search the archives? At http://mail.python.org/mailman/listinfo/tutor you will find links to: http://dir.gmane.org/gmane.comp.python.tutor http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/python-Tutor Kent

Re: [Tutor] Fwd: Help on finding the 1000th prime

2009-11-16 Thread Modulok
Also watch things like letter case on stuff like 'Print' and 'While', they should instead be 'print' and 'while', (all lowercase). -Modulok- On 11/16/09, bob gailer wrote: > >> Here is the code that doesn't work. >> > > Thanks for posting the code. What "doesn't work" mean? > error messages? > u

Re: [Tutor] Fwd: Help on finding the 1000th prime

2009-11-16 Thread bob gailer
Here is the code that doesn't work. Thanks for posting the code. What "doesn't work" mean? error messages? unexpected results? or what? There are several problems in your code. - The candidates you are testing. Walk thru the program and list a few of them and see if you can determine that

Re: [Tutor] Do you use unit testing?

2009-11-16 Thread Serdar Tumgoren
> How many of you guys use unit testing as a development model, or at > all for that matter? >  I just starting messing around with it and it seems painfully slow to > have to write a test for everything you do. Thoughts, experiences, > pros, cons? > I just started with Test-Driven Development mys

[Tutor] Fwd: Help on finding the 1000th prime

2009-11-16 Thread Kent Johnson
-- Forwarded message -- From: Ray Holt Date: Mon, Nov 16, 2009 at 1:55 PM Subject: RE: [Tutor] Help on finding the 1000th prime To: Kent Johnson I hit the send button before I was ready. Here is the code that doesn't work. primeCount = 0 primeCandidate = 2 While primeCount <= 10

[Tutor] Fwd: Help on finding the 1000th prime

2009-11-16 Thread Kent Johnson
Please use reply all to reply to the list -- Forwarded message -- From: Ray Holt Date: Mon, Nov 16, 2009 at 1:34 PM Subject: RE: [Tutor] Help on finding the 1000th prime To: Kent Johnson Basically I can't figure out how to loop through the possible candidates. I am using versi

[Tutor] Do you use unit testing?

2009-11-16 Thread Modulok
List, A general question: How many of you guys use unit testing as a development model, or at all for that matter? I just starting messing around with it and it seems painfully slow to have to write a test for everything you do. Thoughts, experiences, pros, cons? Just looking for input and dif

Re: [Tutor] A way to search archives?

2009-11-16 Thread Serdar Tumgoren
> Is there a way to search the archives? Not sure if someone's developed an official search resource, but I've always found Google search to work well: site:http://mail.python.org/pipermail/tutor/ ___ Tutor maillist - Tutor@python.org To unsubscribe

Re: [Tutor] Help on finding the 1000th prime

2009-11-16 Thread bob gailer
Ray Holt wrote: find the 1000th. prime number. Break this down into 2 separate problems. (I assume 1 is the first prime number) 1 - determining the next prime number 2 - repeating that 1000 times. A while loop is a way to accomplish 2. How do you determine the next prime number? There are man

[Tutor] A way to search archives?

2009-11-16 Thread Ray Holt
Is there a way to search the archives? ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] GzipFile has no attribute '__exit__'

2009-11-16 Thread Sander Sweers
2009/11/16 Kent Johnson : > You might want to report this as a bug against 2.6 and submit this > change as a proposed fix. It's easy to do, see I poked around in the bug tracker and found [1]. It will be in 2.7 and was *not* accepted for 2.6. If anyone wants to add this in themselves see [2]. Gr

Re: [Tutor] proxy switcher - was Re: I love python / you guys :)

2009-11-16 Thread Dave Angel
(Multiple people on this thread have been quoting earlier people without keeping the attribution lines (e.g. yyy wrote: ) so I'm not sure who said what any more. I recognize my own words, of course, but for anybody else, your guess is better than mine) Stephen Nelson-Smith wrote:

Re: [Tutor] Unexpected Result in Test Sequence

2009-11-16 Thread Emmanuel Ruellan
In your code, list list1 never gets emptied. There is another problem : the doc for random.randrange() says it "choose[s] a random item from range(start, stop[, step])" and range(1, 19) goes from 1 included to 19 _not_ included. Your 'd20' is not a 20-sided dice. On Mon, Nov 16, 2009 at 8:18 PM,

Re: [Tutor] Unexpected Result in Test Sequence

2009-11-16 Thread Tim Peters
[kb1...@aim.com] > I'm running a test to find what the experimental average of a d20 is, I don't know what "a d20" is, but your code is picking integers uniformly at random between 1 and 18 inclusive. The expected value is therefore (1+18)/2.0 = 9.5. > and came across a strange bug in my code. >

Re: [Tutor] Unexpected Result in Test Sequence

2009-11-16 Thread Jose Amoreira
Hi! Everytime your program calls function p, list1 is appended to. It keeps on getting bigger and bigger. The function adds all the elements of the list, but the total is divided by 1000, even if the list is already much longer that 1000! And there's another thing. When var1 and var2 are intege

Re: [Tutor] Unexpected Result in Test Sequence

2009-11-16 Thread vince spicer
On Mon, Nov 16, 2009 at 1:18 PM, wrote: > Hello Tutor list. > I'm running a test to find what the experimental average of a d20 is, and > came across a strange bug in my code. > import random > list1 = [] > def p(): > d = 0 > for number in range(1,1000): > t = random.randrange(1,19) >

Re: [Tutor] Unexpected Result in Test Sequence

2009-11-16 Thread Jeff R. Allen
When you declare list1 before "def p()" you are making it global. That means it will keep its values between invocations of p(). When you start function p, you don't reset list1 to empty. You divide each time by 1000, and but your list1 list is growing and growing and growing. That's why the total

[Tutor] Unexpected Result in Test Sequence

2009-11-16 Thread kb1pkl
Hello Tutor list. I'm running a test to find what the experimental average of a d20 is, and came across a strange bug in my code. import random list1 = [] def p(): d = 0 for number in range(1,1000): t = random.randrange(1,19) list1.append(t) for value in list1: d+=v

Re: [Tutor] proxy switcher - was Re: I love python / you guys :)

2009-11-16 Thread Stephen Nelson-Smith
Evening, > Yes, you can, but not this way.  I'm guessing the op was changing his mind > back and forth, between having two files, one for reading and one for > writing, and trying to do it in place.  The code does neither/both. Well, just neither I think! I didn't check if 'rw' was possible. My

Re: [Tutor] proxy switcher - was Re: I love python / you guys :)

2009-11-16 Thread Dave Angel
Luke Paireepinart wrote: Here's what I knocked up over lunch. It doesn't cover the moving of the file, I don't like that it's deep-nested, and I've not tested it, but I welcome criticism and feedback: files = ['file1', 'file2', 'file3', 'file4'] settings = ['export http_proxy=', 'ftp_proxy=']

Re: [Tutor] Help on finding the 1000th prime

2009-11-16 Thread Kent Johnson
On Mon, Nov 16, 2009 at 10:56 AM, Ray Holt wrote: > I have posted this on other lists, but have just discovered this one. Can > someone give me help on writing the code necessary to find the 1000th. prime > number. I know I will have to use a while loop, but I can't seem to get the > body of the c

Re: [Tutor] Help on finding the 1000th prime

2009-11-16 Thread christopher . henk
mrhol...@sbcglobal.net wrote on 11/16/2009 10:56:07 AM: > I have posted this on other lists, but have just discovered this one. Welcome to the list. I am sure you will find plenty of folks here who will be happy to help you. > Can someone give me help on writing the code > necessary

[Tutor] Help on finding the 1000th prime

2009-11-16 Thread Ray Holt
I have posted this on other lists, but have just discovered this one. Can someone give me help on writing the code necessary to find the 1000th. prime number. I know I will have to use a while loop, but I can't seem to get the body of the code to function rightly. I would appreciate any help. I am

Re: [Tutor] proxy switcher - was Re: I love python / you guys :)

2009-11-16 Thread Luke Paireepinart
> Here's what I knocked up over lunch. It doesn't cover the moving of > the file, I don't like that it's deep-nested, and I've not tested it, > but I welcome criticism and feedback: > > files = ['file1', 'file2', 'file3', 'file4'] > settings = ['export http_proxy=', 'ftp_proxy='] > > for file in f

Re: [Tutor] proxy switcher - was Re: I love python / you guys :)

2009-11-16 Thread Stephen Nelson-Smith
Hi, >> When i use our company's LAN i set my proxy variable by hand in .bashrc. >> There are 4 files to insert proxy variable: >> >> in ~/.bashrc, /root/.bashrc, /etc/wgetrc and /etc/apt/apt.conf. >> >> The last one is actually rename e.g. mv to apt.conf to activate proxy and mv >> to apt.conf.bak

Re: [Tutor] I love python / you guys :)

2009-11-16 Thread Stephen Nelson-Smith
Hello all, On Mon, Nov 16, 2009 at 6:58 AM, Stefan Lesicnik wrote: > hi, > > Although not a question, i just want to tell you guys how awesome you are! +1 I've been a happy member of this list for years, even though I've taken a 3 year Ruby sabbatical! I've always found it to be full of invalu

Re: [Tutor] Tutor Digest, Vol 69, Issue 73

2009-11-16 Thread Mario Cavett
> > Alan G > > ___ > Tutor maillist ?- ?tu...@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > > > -- > Regards, > Lloyd > > ___

Re: [Tutor] GzipFile has no attribute '__exit__'

2009-11-16 Thread Kent Johnson
On Mon, Nov 16, 2009 at 7:15 AM, Sander Sweers wrote: > This triggered my to dig into this a bit. This is not fixed untill > python 3.1 but seems easilly added to the ZipFile class. My attempt to > backport this from python 3.1's gzip.py below seems to work. > > Greets > Sander > > import gzip >

Re: [Tutor] I love python / you guys :)

2009-11-16 Thread Luke Paireepinart
Accidental off-list reply. On Mon, Nov 16, 2009 at 5:36 AM, bibi midi wrote: > > In the same lines of if-you-can-think-of-anything-python-can-do-it i got > inspired to ask a question for the gurus: > > When i use our company's LAN i set my proxy variable by hand in .bashrc. > There are 4 files to

Re: [Tutor] Writing code while tired, counterproductive?

2009-11-16 Thread Albert-Jan Roskam
I find that switching to a completely different approach or strategy becomes more difficult when tired. Depending on the context, that could be called persistence of perseverence (begin good or bad, respectively). However, in my opinion, not being able to view things from a different angle is us

Re: [Tutor] GzipFile has no attribute '__exit__'

2009-11-16 Thread Sander Sweers
2009/11/16 Dave Angel : > Alternatively, you could subclass it, and write your own.  At a minimum, the > __exit__() method should close() the stream. This triggered my to dig into this a bit. This is not fixed untill python 3.1 but seems easilly added to the ZipFile class. My attempt to backport t

[Tutor] proxy switcher - was Re: I love python / you guys :)

2009-11-16 Thread Stefan Lesicnik
On Mon, Nov 16, 2009 at 1:36 PM, bibi midi wrote: > > > On Mon, Nov 16, 2009 at 1:58 AM, Stefan Lesicnik wrote: >> >> hi, >> >> Although not a question, i just want to tell you guys how awesome you are! >> >> I am not a programmer, i can do a bit of bash. I have never officially >> learnt program

Re: [Tutor] GzipFile has no attribute '__exit__'

2009-11-16 Thread Dave Angel
Stephen Nelson-Smith wrote: I'm trying to write a gzipped file on the fly: merged_log = merge(*logs) with gzip.open('/tmp/merged_log.gz', 'w') as output: for stamp, line in merged_log: output.write(line) But I'm getting: Traceback (most recent call last): File "./magpie.py", lin

Re: [Tutor] GzipFile has no attribute '__exit__'

2009-11-16 Thread Kent Johnson
On Mon, Nov 16, 2009 at 5:58 AM, Stephen Nelson-Smith wrote: > I'm trying to write a gzipped file on the fly: > > merged_log = merge(*logs) > > with gzip.open('/tmp/merged_log.gz', 'w') as output: >    for stamp, line in merged_log: >        output.write(line) > > But I'm getting: > > Traceback (m

Re: [Tutor] I love python / you guys :)

2009-11-16 Thread bibi midi
On Mon, Nov 16, 2009 at 1:58 AM, Stefan Lesicnik wrote: > hi, > > Although not a question, i just want to tell you guys how awesome you are! > > I am not a programmer, i can do a bit of bash. I have never officially > learnt programming, but numerous times looked at some perl, c, java > and never

Re: [Tutor] Unexpected iterator

2009-11-16 Thread Kent Johnson
On Mon, Nov 16, 2009 at 12:17 AM, spir wrote: > Le Sun, 15 Nov 2009 19:23:33 -, > "Alan Gauld" s'exprima ainsi: > >> What does 'unpack' mean?  I've seen a few Python errors about packing >> and unpacking.  What does it mean? > > Unpacking is rarely needed. It matches some kind of problems. N

[Tutor] GzipFile has no attribute '__exit__'

2009-11-16 Thread Stephen Nelson-Smith
I'm trying to write a gzipped file on the fly: merged_log = merge(*logs) with gzip.open('/tmp/merged_log.gz', 'w') as output: for stamp, line in merged_log: output.write(line) But I'm getting: Traceback (most recent call last): File "./magpie.py", line 72, in with gzip.open('

Re: [Tutor] Unexpected iterator

2009-11-16 Thread Alan Gauld
"spir" wrote Unpacking is rarely needed. It matches some kind of problems. ... (parens not needed) It's just an elegant manner to avoid indexing -- right? Regarding tuple unpacking... Absolutely, its a convenience. Regarding struct unpacking, its an absolute necessity in getting data out

Re: [Tutor] nul file in Windows

2009-11-16 Thread Timo
Dave Angel schreef: Timo List wrote: For my program I disable the py2exe log feature by routing output to the nul-file. Code: if win32 and py2exe: sys.stdout = open("nul", "w") sys.stderr = open("nul", "w") This always worked fine. Today, I received an email fr

Re: [Tutor] Writing code while tired, counterproductive?

2009-11-16 Thread Luke Paireepinart
I hate to be the odd one out here, but I actually find that I am extremely productive when I'm tired. It's easier for me to commit completely to the code, when I'm well-rested I dream about running through fields of sunflowers and such, get distracted more easily. The code I write when I'm tired

[Tutor] Apologies for sent spam

2009-11-16 Thread Albert-Jan Roskam
Hi,   I just noticed that a spam message was sent with my email address. Apologies. I have no idea what caused that. I'll check my windows machine for viruses. Or could it have some other cause? Perhaps I should also change my password. Cheers!! Albert-Jan ~~~

Re: [Tutor] I love python / you guys :)

2009-11-16 Thread OkaMthembo
Stefan, you echoed my thinking too :) On Mon, Nov 16, 2009 at 8:58 AM, Stefan Lesicnik wrote: > hi, > > Although not a question, i just want to tell you guys how awesome you are! > > I am not a programmer, i can do a bit of bash. I have never officially > learnt programming, but numerous times l