[Tutor] newbie: Reading text file

Grant Hagstrom grantahagstrom at gmail.com
Fri Jun 1 21:21:13 CEST 2007


Alan,

Good point. Earlier I was trying to figure out how the script worked, and
having else: print "break" seemed to help with that. For example, in one
version that I was tinkering with, break was printed 17 times. In the
current version, break is printed twice.

hope that makes sense,

Grnat

On 6/1/07, ALAN GAULD <alan.gauld at btinternet.com> wrote:
>
> Grant,
>
> > My question is, is it possible to strip out multiple characters at once?
>
>
> Kent answered that bit.
>
> > started = False
> > for line in file('mylist.py'):
> >     if 'jobs' in line and not started:
> > ...
> >    if ']' not in line and started:
> >        jobs.append(line.strip('...'))
> >    else: print "break"
>
> Are you sure you only want to print break? If so the code will
> continue processing lines after the end of your list. My break
> command will exit the loop when it finds the ] character. If you
> don't want to use break you could set started to False again.
>
> Alan G.
>
> ------------------------------
> New Yahoo! Mail is the ultimate force in competitive emailing. Find out
> more at the Yahoo! Mail Championships<http://uk.rd.yahoo.com/mail/uk/taglines/gmail_com/championships/games/*http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk/>.
> Plus: play games and win prizes.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/b4dc6176/attachment.html 


More information about the Tutor mailing list