Last active
December 28, 2015 22:43
-
-
Save xiantail/04282138936438255268 to your computer and use it in GitHub Desktop.
Introducing Python / Chapter12 pdb debugging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process_cities(filename): | |
with open(filename, 'rt') as file: | |
for line in file: | |
line = line.strip() | |
if 'quit' in line.lower(): | |
return | |
country, city = line.split(',') | |
city = city.strip() | |
country = country.strip() | |
print(city.title(), country.title(), sep=',') | |
if __name__ == '__main__': | |
import sys | |
process_cities(sys.argv[1]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def process_cities(filename): | |
with open(filename, 'rt') as file: | |
for line in file: | |
line = line.strip() | |
if 'quit' == line.lower(): #changed here | |
return | |
country, city = line.split(',') | |
city = city.strip() | |
country = country.strip() | |
print(city.title(), country.title(), sep=',') | |
if __name__ == '__main__': | |
import sys | |
process_cities(sys.argv[1]) |
We can make this file beautiful and searchable if this error is corrected: It looks like row 4 should actually have 2 columns, instead of 1. in line 3.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
France, Paris | |
venezuela,caracas | |
LithuniA,vilinius | |
quit |
We can make this file beautiful and searchable if this error is corrected: It looks like row 15 should actually have 2 columns, instead of 1. in line 14.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
argentina,buenos aires | |
bolivia,la paz | |
brazil,brasilia | |
chile,santiago | |
colombia,Bogotá | |
ecuador,quito | |
falkland islands,stanley | |
french guiana,cayenne | |
guyana,georgetown | |
paraguay,Asunción | |
peru,lima | |
suriname,paramaribo | |
urguay,montevideo | |
venezuela,caracas | |
quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment