i'm writing program in python read file , turn file a list of words. @ moment gives me 4 lists (one each line of file) function rstrip()
doesn't seem working , i'm not sure why.
fname = raw_input("enter file name: ") fread = open(fname) line in fread: line = line.rstrip() lst = line.split() print lst
i going speculate want join lists each line. can list.extend
.
lst = [] line in fread: line = line.rstrip() lst.extend(line.split()) print lst
another way of doing might
lst = fread.read().strip().split()
also, in either case, don't forget close file.
fread.close()
Comments
Post a Comment