Module 24 - Blank File

0 Michael Boniface · October 21, 2015
Working along with Module 24 the program executes fine but the resulting file contains no data, anyone any idea why that might be?
Here's the code written using Python v3.5 on Mac

from urllib import request

goog_url = 'http://real-chart.finance.yahoo.com/table.csv?s=GOOG&d=9&e=21&f=2015&g=d&a=2&b=27&c=2014&ignore=.csv'

def download_stock_data(csv_url):
response = request.urlopen(csv_url)
csv = response.read()
csv_str = str()
lines = csv_str.split("\\n")
dest_url = r'goog.csv'
fx = open(dest_url, "w")
for line in lines:
fx.write(line + "\n")
fx.close()

download_stock_data(goog_url)

Post a Reply

Replies

Oldest  Newest  Rating
0 sfolje 0 · October 22, 2015
Hi, you 've got a typo (spelling-copy-paste mistake).

In that situations when i have alot of lines, and wanna check for a mistake, i help myself by commenting out some lines, and making sure that uncommented code, that i wrote, works as it should. And if it doesnt, i comment more, and if works, i check those commented lines, and so on.
feedback
  • 1

Python

106,941 followers
About

This section is all about snakes! Just kidding.

Links
Moderators
Bucky Roberts Administrator