[Tutor] Reading elements in a file

Greg Christian glchristian at comcast.net
Wed May 4 20:37:39 CEST 2011


I am kind of stuck on what is probably a simple thing:

If we have a file of words like this: “first”,”word”,”in”,”that”,”another”,”part”,”of”,”this”

f = open('words.txt', "r")
    words = f.read()

will read the whole file, is there a way to read just the words: first word in that another part of this

I guess I have to separate on the “,” but I am not quite sure how to go about this.

Any input would be appreciated.

Regards,

Greg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110504/f4bdb7b0/attachment-0001.html>


More information about the Tutor mailing list