I have a list of addresses and latitude,longitudes which I am printing from a text file. It has a few 0's so I am using try
and except
blocks.
Now I want to save the output to a CSV file and I am trying this code:
with open("qwe.txt",'r') as fp, open("qwert.txt",'w') as fr:
for line in fp:
#try:
g= geocoder.google(line)
#print(g.address,g.latlng)
# except:
#print(0,0)
writer = csv.writer(fr, delimiter=',')
writer.writerows(zip(g.address,g.latlng))
fp.close()
but the loop is exiting when there is 0 occurence. I want to write try
and catch
on a single line so that I can print the output to a CSV.
I tried using lambda
but looks like lamda
doesn't work for try
and except
.