[Tutor] newbie: Reading text file

Preecha Bundrikwong preecha88 at gmail.com
Fri Jun 1 08:04:28 CEST 2007

Dear Tutors,

I have a text file (mylist.py actually), it contains exactly below:
# file mylist.py
jobs = [

I want to write another script and get the list "jobs" from the above

Is it possible for me to get the variable 'jobs' and its value from the file
(as a list)? What I'm trying to do now is open the file, readlines in a
loop, once it finds the line with "jobs = [", then start accumulate (append)
a varible until it hits the line with "]" then stop. This is too
complicated. I believe there should be an easier way in Python. Can anyone
guide me, please.

Thanks in advance,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070601/9c490735/attachment.html 

More information about the Tutor mailing list