Skip to content

Instantly share code, notes, and snippets.

@xiantail
Last active December 28, 2015 22:43
Show Gist options
  • Save xiantail/04282138936438255268 to your computer and use it in GitHub Desktop.
Save xiantail/04282138936438255268 to your computer and use it in GitHub Desktop.
Introducing Python / Chapter12 pdb debugging
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])
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.
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.
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