Brian are you using 1.5.2? How can I translate the code of b = [i.strip() for i in f.readlines( )] to 1.5.2 syntax as it does not know it. Also test.txt gots more complicated on y end: #Input File Name /vobs/qa/stf/ctf/src/sample/tpu/log/tpTcTNLC9_4/tp_acc.1 #Output File Name /vobs/qa/stf/ctf/src/sample/tpu/log/tpTcTNLC9_4/tp_acc.1.arr #Name #IUT Name #Stackname Cc Tpt Sn Sm #Build ALL 1 #Input File List /vobs/qa/stf/ctf/src/sample/tpu/log/tpTcTNLC9_4/tp_acc.1 /vobs/qa/stf/ctf/src/sample/tpu/log/tpTcTNLC9_4/tp_acc.2 /vobs/qa/stf/ctf/src/sample/tpu/log/tpTcTNLC9_4/tp_acc.3 /vobs/qa/stf/ctf/src/sample/tpu/log/tpTcTNLC9_4/tp_acc.4 /vobs/qa/stf/ctf/src/sample/tpu/log/tpTcTNLC9_4/tp_acc.5 I use the following code to get the values from text.txt file: iniInfo = [] f = open('text.txt','r') iniInfo = f.readlines() a = string.strip(iniInfo[1]) b = string.strip(iniInfo[3]) c = string.strip(iniInfo[5]) d = string.strip(iniInfo[7]) e = string.strip(iniInfo[9]) e = string.strip(iniInfo[11]) f = ???? I want to put the list contents stored in file in list f.. how cna I do that??? Thanks --- Brian Quinlan <BrianQ at ActiveState.com> wrote: > I don't know for sure but it looks like you want > each list element on a new > line in the file. If so, try this: > > import os > > a = ['a','b','c'] > > f = open( r'c:\test.txt', 'w' ) > f.write( os.linesep.join( a ) ) > > f = open( r'c:\test.txt', 'r' ) > # Just strips the surrounding whitespace from the > line > b = [i.strip() for i in f.readlines( )] > print b > > Ed wrote: > > I currently have a list and woulr like to store > the contents into a > > text fiel whihc I can read back ... > > > > For example: > > a = ['a','b','c','d'] > > #do something like > > fd = open('txt.txt','w') > > fd.write(a) > > Traceback (innermost last): > > File "<stdin>", line 1, in ? > > TypeError: read-only buffer, list > > > > What to do?? > > And I can't use pickle ... > > > > later on I would like to read it back... > > > > fd = open('txt.txt','r') > > > > iniInfo = fd.readlines() > > b=[] > > b = iniInfo[0] > > # copy list contents into c > > map(c.append,b) > > > > I think this also not work right > > ? > > Can someone kindly tell me how to do write and > read a list to a file? > > > > Thanks > > > > > > > > -- > > > http://mail.python.org/mailman/listinfo/python-list > > > __________________________________________________ Do You Yahoo!? Yahoo! Auctions - buy the things you want at great prices http://auctions.yahoo.com/
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4