A problem with list

export at hope.cz export at hope.cz
Mon Dec 13 15:49:41 CET 2004


The following code
##############
import string
MyList=['abc','def']
for i in MyList:
print i
###############

works as I expect that is I get
abc
def

but when I have Mylist in a file and I read it from the file it does
not work as I expect.
#########
import string
ff=open('C:\\Robotp\\MyFile.txt','r') # read MyList from a file
MyList=ff.read()
for i in MyList:
print i
###########
I will get
[
'
a
b
c
'
,
'
d
e
f
'
]

where my MyFile.txt looks like this:
['abc','def']

Where is a problem?
Thanks for help
Lad




More information about the Python-list mailing list