Answer the question
In order to leave comments, you need to log in
The simplest parsing in python?
What is up, programmer.
Here is the actual code:
from urllib import request
goog_url = "http://real-chart.finance.yahoo.com/table.csv?s=GOOGL.BA&d=9&e=15&f=2015&g=d&a=8&b=26&c=2011&ignore=.csv"
def download_csv_file (csv_file):
response = request.urlopen(csv_file)
csv = response.read()
csv_str = str(csv)
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_csv_file(goog_url)
Answer the question
In order to leave comments, you need to log in
.split() is a method of a string object, splits a string by a given character or set of characters, returns a list of strings.
The r prefix means that escaping should be ignored inside the string, it should be used "as is" (short for raw). In this particular case, it doesn't matter.
split is a string method. Splits a string at the given delimiter.
r - raw string designation.
Generally it is necessary to look the documentation on lines.
https://docs.python.org/2/library/string.html
stackoverflow.com/questions/2081640/what-exactly-d...
for csv parsing it is better to use
https://docs.python.org/2/ library/csv.html
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question