Question: I have a question. I have a txt file save on my computer and I have a python program that supposed to edit the txt
I have a question. I have a txt file save on my computer and I have a python program that supposed to edit the txt file to arrange the information in a table. The program runs, but when reopen the txt file, no changes made to it. I can't figure out what I am missing from the python program to make the changes to the txt file.
Here is the python program:
f=open("CityStateData.txt", "r") for c in f: # extract the city name from the element of the list cityname = c.split(",")[0].strip() # after extracting the city name, extract the state # the state code is two characters long # strip is ued to remove leading and trailing white spaces state = (c.split(",")[1]).strip()[0:2].strip() # extract the zip code from the element. It is the last token # of the given element zipcode = (c.split(",")[1]).strip()[2:].strip() # display the result in tabular form using the format # function of the str class print("{0:19} {1:2} {2:5}".format(cityname, state, zipcode)) f.close()
Advise please!
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
