Newbie Question
Moshe Zadka
moshez at math.huji.ac.il
Fri Apr 28 00:56:08 EDT 2000
On Thu, 27 Apr 2000, Arnaldo Riquelme wrote:
> Suppose I have a file name tick.tkr that looks like this
>
> SUNW.
> MFST.
> FOO.
> SPAM.
> MOO.
> End_Of_File
>
> I want to read the file into a list
>
> myfile = open("tick.tkr", "r")
> mylist = myfile.readlines()
>
> Now I have mylist with the contents of tick.tkr. "mylist" looks like this
> ['SUNW.\012', 'MSFT.\012', ..........'End_of_File/012']
>
> How do I read the file into a list without getting the newline character, so
> I can accomplish this
>
> for tic in mylist:
> #create file tic.prn
>
> I know the other P language has something like 'chop' or something like
> that, but I'm not going there.
Try "string.strip". In your case, it should do fine.
--
Moshe Zadka <mzadka at geocities.com>.
http://www.oreilly.com/news/prescod_0300.html
http://www.linux.org.il -- we put the penguin in .com
More information about the Python-list
mailing list