How does the code know when to split into a line?
Question: So I was learning on how to download files from the web using python but got a
bit thrown by one part of the code.

Here is the code:

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

I don't quite understand the code in the variable lines. How does it know when
to split into a new line on a csv file ?


Answer: A csv file is essentially just a text file will comma separated data but they
also contain new lines (via the newline ascii character).

If there a csv file with a long single comma separated line for line in lines:
would only see the single line.

You can open it up in notepad++ or something to see the raw .csv file. Excel
will put data seperated by commas in a cell,and data on a new line into a new
row.

