[Tutor] Reading List from File

S Python spython01 at gmail.com
Thu Jul 31 15:07:22 CEST 2008

Hi Everyone,

I am trying to read a comma-delimitted list ("aaa","bbb","ccc") from a text
file and assign those values to a list, x, such that:

x = ["aaa", "bbb", "ccc"]

The code that I have come up with looks like this:

>>> x = []
>>> f = open(r'c:\test.txt', 'r')
>>> x.extend(f.readlines())
>>> x

If you look closely, there is an extra pair of single quotes (') that
encapsulates the string.  Therefore, len(x) returns 1, instead of 3.  Is
there a function to "separate" this list out?  I hope my question makes

Thanks in advance.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080731/9f329f25/attachment.htm>

More information about the Tutor mailing list