[Tutor] newbie: Reading text file
ALAN GAULD
alan.gauld at btinternet.com
Fri Jun 1 14:04:18 CEST 2007
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. Plus: play games and win prizes.
http://uk.rd.yahoo.com/evt=44106/*http://mail.yahoo.net/uk
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/30526897/attachment.htm
More information about the Tutor
mailing list