Looping Problem (Generating files - only the last record generates a file)
johan.appelgren at gmail.com
johan.appelgren at gmail.com
Wed Oct 26 05:14:01 EDT 2005
You have only indented the first line in the for-loop, so for each line
in the file you split the line into town and latlong. Then after you
have split the last line in the file you write a new file with the last
result in the for-loop.
What you want is probably something like this:
#! python
HEADER = "This page displays longitude-latitude information"
SUBHEADER = "City"
for line in open("datafile.txt"):
town, latlong = line.split('\t')
f = open(town + ".txt", "w+")
f.write(HEADER + "\n")
f.write(SUBHEADER + ": " + town + "\n")
f.write("LAT/LONG" + ": " + latlong + "\n")
f.close()
# end
/Johan
More information about the Python-list
mailing list