Re: 'While' question

2008-08-23 Thread Ben Keshet
Wojtek Walczak wrote: On Fri, 22 Aug 2008 10:42:13 -0400, Ben Keshet wrote: Thanks. I tried to use 'for' instead of 'while' as both of you suggested. It's running well as my previous version but breaks completely instead of just skipping the empty file. I suspect the reason is that this

Re: 'While' question

2008-08-23 Thread Scott David Daniels
Ben Keshet wrote: ... I ended up using another method as someone suggested to me. I am still not sure why the previous version got stuck on empty files, while this one doesn't: receptors = ['A' 'B'] *** Alarm bells *** Do you mean ['AB'], or do you mean ['A', 'B']? ...(more code one way)

Re: 'While' question

2008-08-22 Thread Bruno Desthuilliers
John Machin a écrit : (snip) A quick rule of thumb for Python: if your code looks ugly or strained or awkward, it's probably also wrong. +1 QOTW -- http://mail.python.org/mailman/listinfo/python-list

Re: 'While' question

2008-08-22 Thread Ben Keshet
Thanks. I tried to use 'for' instead of 'while' as both of you suggested. It's running well as my previous version but breaks completely instead of just skipping the empty file. I suspect the reason is that this part is inside another 'for' so it stops everything. I just want to it to

Re: 'While' question

2008-08-22 Thread Wojtek Walczak
On Fri, 22 Aug 2008 10:42:13 -0400, Ben Keshet wrote: Thanks. I tried to use 'for' instead of 'while' as both of you suggested. It's running well as my previous version but breaks completely instead of just skipping the empty file. I suspect the reason is that this part is inside another

Re: 'While' question

2008-08-22 Thread Ben Finney
Bruno Desthuilliers [EMAIL PROTECTED] writes: John Machin a écrit : (snip) A quick rule of thumb for Python: if your code looks ugly or strained or awkward, it's probably also wrong. +1 QOTW Merely a special case of the truism that Your code is probably wrong (regardless of any other

'While' question

2008-08-21 Thread Ben Keshet
Hi - I am writing now my second script ever in python and need some help with 'while'. I am reading text from a set of files and manipulating the data somehow. I use 'while 'word' not in line' to recognize words in the texts. Sometimes, the files are empty, so while doesn't find 'word' and

Re: 'While' question

2008-08-21 Thread Wojtek Walczak
On Thu, 21 Aug 2008 18:01:25 -0400, Ben Keshet wrote: somehow. I use 'while 'word' not in line' to recognize words in the texts. Sometimes, the files are empty, so while doesn't find 'word' and runs forever. I have two questions: 1) how do I overcome this, and make the script skip the empty

Re: 'While' question

2008-08-21 Thread Ben Keshet
Thanks for the reference. I tried it with a general example and got it to work - I used an index that counts up to a threshold that is set to break. It does not work though with my real code. I suspect this is because I cannot really read any lines from an empty file, so the code gets stuck

Re: 'While' question

2008-08-21 Thread Larry Bates
Ben Keshet wrote: Thanks for the reference. I tried it with a general example and got it to work - I used an index that counts up to a threshold that is set to break. It does not work though with my real code. I suspect this is because I cannot really read any lines from an empty file, so

Re: 'While' question

2008-08-21 Thread John Machin
On Aug 22, 9:01 am, Ben Keshet [EMAIL PROTECTED] wrote: Thanks for the reference. I tried it with a general example and got it to work - I used an index that counts up to a threshold that is set to break. It does not work though with my real code. I suspect this is because I cannot really