I'm changing so much the code that I got lost now. Code so far: http://pastebin.com/u4xwZuyJ
I'm getting this error. 'value = float(row[-1])' is getting the values OK, but when I do 'rates[row[0]] = value' it screws things up. =========================== Traceback (most recent call last): File "C:.../currency.py", line 48, in <module> date = get_rates() File "C:.../currency.py", line 40, in get_rates print(rates[row[0]] + " / VALUE : " + str(value)) KeyError: 'U.S. dollar ' Process finished with exit code 1 =========================== 2014-08-30 21:43 GMT-03:00 Danny Yoo <d...@hashcollision.org>: > Hi Juan, > > Wait, you are working with a CSV file, right? You should not be > trying to parse this by hand if you can avoid it: there's a 'csv' > parser library in the Standard Library. > > https://docs.python.org/3.1/library/csv.html > > So: > > #################################### > import codecs > import urllib.request > import csv > > urlString = "http://www.bankofcanada.ca/en/markets/csv/exchange_eng.csv" > rawFile = urllib.request.urlopen(urlString) > decodedFile = codecs.getreader("utf-8")(rawFile) > rows = csv.reader(decodedFile) > > for row in rows: > print(repr(row)) > ####################################### > > > should take better advantage of what the Standard Library provides > you: then you just deal with the records. You might have to do a > little to filter out the beginning comment lines, but that shouldn't > be too bad. >
_______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor