csv - Print in Reverse Order Python -
this question has answer here:
- read file in reverse order using python 11 answers
f = urlopen ('http://ichart.finance.yahoo.com/table.csv?s=aapl&d=4&e=29&f=2014&g=d&a=8&b=22&c=1981&ignore=.csv') sys.stdout = open('output.csv', 'w') p = f.read() print p f.close
this opens (or creates) file called output.csv , outputs lines downloaded file local csv. how reverse order lines printed in?
if there header in input, might want print header first; followed remaining lines.
f = urlopen ('http://ichart.finance.yahoo.com/table.csv?s=aapl&d=4&e=29&f=2014&g=d&a=8&b=22&c=1981&ignore=.csv') open('output.csv', 'w') out: # print header first out.write(f.readline()) # print reversed lines line in reversed(f.readlines()): out.write(line) f.close() # !!!
Comments
Post a Comment