adding items from a text file to a list

Don Arnold darnold02 at sprynet.com
Tue Oct 30 20:29:55 EST 2001


i'm sure this will be answered a lot more succinctly and/or elegantly by
others on the list, but here it goes:

infile = open("c:/windows/desktop/myfile.txt","r")
filecontents = infile.readlines()
infile.close()

thelist = []

for line in filecontents:
  commentstart = line.find("(")
  if commentstart > 0:
    thelist.append(line[:commentstart])
  else:
    thelist.append(line)



More information about the Python-list mailing list