Re: String from File -> List without parsing

2005-09-04 Thread Gregor Horvath
John Machin wrote: >> f = file("I050901.ids").readlines() > > Y3K bug alert :-) but then there is Python 3000 and Hurd, which solves all problems of this universe :-) > Something like this: > > >>> def munch(astrg): > ...return [x[1:-1] for x in astrg.rstrip("\n")[1:-1].split(", ")] T

Re: String from File -> List without parsing

2005-09-04 Thread John Machin
Gregor Horvath wrote: > Hi, > > given the dynamic nature of python I assume that there is an elegant > solution for my problem, but I did not manage to find it. > > I have a file that contains for example on line: > ['147', '148', '146'] > when I read the file > f = file("I050901.ids").readline

Re: String from File -> List without parsing

2005-09-04 Thread Jean-François Doyon
Gregor, You want to use eval(): Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> eval('[3,54,5]') [3, 54, 5] >>> Cheers, J.F. Gregor Horvath wrote: > Hi, > > given the dynamic nature of

String from File -> List without parsing

2005-09-04 Thread Gregor Horvath
Hi, given the dynamic nature of python I assume that there is an elegant solution for my problem, but I did not manage to find it. I have a file that contains for example on line: ['147', '148', '146'] when I read the file f = file("I050901.ids").readlines() I have a string f[0] == "['147