Re: [Tutor] newbie: Reading text file

2007-06-03 Thread Preecha Bundrikwong
Dear all, Thanks for all your help. I followed Alan's suggestion -- dealing with the directory search path, by the method sys.path.append(). At first I thought it would mess up the whole sys.path after running the script. But it actually doesn't. Thanks again! Regards, PB ___

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread Grant Hagstrom
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 O

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread Alan Gauld
"Grant Hagstrom" <[EMAIL PROTECTED]> wrote > The reason why I didn't want the import solution is that I am > learning > python because I want to parse text data. This problem was perfect > practice. The best book on this topic is David Mertz' book Text Processing in Python. The draft version i

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread Kent Johnson
Grant Hagstrom wrote: > Thanks for the links. I'll check them out. You don't happen to have any > parsing tutorials bookmarked somewhere do you? I'm already exploring > http://gnosis.cx/TPiP/. It's pretty heavy though. For general text processing, you might want to browse the Text section of t

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread ALAN GAULD
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: p

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread Grant Hagstrom
Kent, Your multistrip tid-bit worked perfectly. Thanks! The reason why I didn't want the import solution is that I am learning python because I want to parse text data. This problem was perfect practice. Thanks for the links. I'll check them out. You don't happen to have any parsing tutorials b

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread Kent Johnson
Grant Hagstrom wrote: > Thanks for your help Alan. > > I found that when I used the code, it did returne a list but it is > riddled with formatting characters. > My question is, is it possible to strip out multiple characters at once? Yes, just pass multiple characters to strip(), e.g. line = li

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread Grant Hagstrom
Thanks for your help Alan. I found that when I used the code, it did returne a list but it is riddled with formatting characters. My question is, is it possible to strip out multiple characters at once? started = False for line in file('mylist.py'): if 'jobs' in line and not started: j

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread ALAN GAULD
Hi Grant, > I'm a newbie and this is my first script submission to this email list. > I was able to parse out the jobs list into a string: "jobs = [ . . ." > However, I can't make python interpret that string as the command "jobs = [ > some list]" There are ways of doing that but unless you are

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread Grant Hagstrom
Hey, I'm a newbie and this is my first script submission to this email list. I was able to parse out the jobs list into a string: "jobs = [ . . ." However, I can't make python interpret that string as the command "jobs = [ some list]" #SCRIPT # open the file and assign it to the variable "thefi

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread Alan Gauld
"Preecha Bundrikwong" <[EMAIL PROTECTED]> wrote > I have a text file (mylist.py actually), it contains exactly below: > --- > # file mylist.py > jobs = [ >'Lions', >'SysTest', >] > > > I want to write another script and get the list "jobs" from

Re: [Tutor] newbie: Reading text file

2007-06-01 Thread Duncan Gibson
> I have a text file (mylist.py actually), it contains exactly below: > --- > # file mylist.py > jobs = [ > 'Lions', > 'SysTest', > 'trainDD', > 'Cats', > 'train', > 'sharks', > 'whale', > ] > > > I want

[Tutor] newbie: Reading text file

2007-05-31 Thread Preecha Bundrikwong
Dear Tutors, I have a text file (mylist.py actually), it contains exactly below: --- # file mylist.py jobs = [ 'Lions', 'SysTest', 'trainDD', 'Cats', 'train', 'sharks', 'whale', ] I want to write another script