Parse online comma delimited text file in Python 3.5
<p>I guess this is a combination of two questions - read online text file and then parse the result into lists. I tried the following code, which can read the file into byte file but not able to convert into list</p>

<pre><code>import urllib
CFTC_URL = r"http://www.cftc.gov/dea/newcot/FinFutWk.txt"
CFTC_url = urllib.request.urlopen(CFTC_URL)
output = CFTC_url.read().decode('utf-8')
</code></pre>

<p>Assuming you want to interpret the file as a table you want to first get the rows by using <a href="http://stackoverflow.com/questions/172439/how-do-i-split-a-multi-line-string-into-multiple-lines">split</a>. Then you can get the columns by splitting each row again.</p>

<pre><code>import urllib.request
CFTC_URL = r"http://www.cftc.gov/dea/newcot/FinFutWk.txt"
CFTC_url = urllib.request.urlopen(CFTC_URL)
output = CFTC_url.read().decode('utf-8')
lines = output.split("\r\n"))) # split on newline
print(lines[0]) # first line "CANADIAN DOLLAR ..."
columns_0 = lines[0].split(",") # split on ,
print(columns[0]) # first column of first line
</code></pre>

<p>You can then iterate through the list of lines and for each entry in lines you can iterate through the columns.</p>

python csv urllib delimited-text