Friday, 15 July 2011

read line from file but store as list (python) -



read line from file but store as list (python) -

i want read specific line in textfile , store elements in list.

my textfile looks

'item1' 'item2' 'item3'

i end list every letter element

what tried

line = file.readline() u in line: #do

you can try:

for u in line.split():

which assumes there whitespaces between each item. otherwise you'll iterate on str , iterate character character.

you might want do:

u = u.strip('\'')

to rid of '

python

No comments:

Post a Comment