blake on a whim

Posts tagged python

2 notes &

python readline and tab-delimited excel text data

Answer: use reader = open(source,’rU’) instead of the normal reader = open(source,’r’) to enable universal newline support.  http://docs.python.org/library/functions.html#open

Yesterday I had all kinds of trouble reading tab-delimited text I had used excel to clean up and reformat.  I scoured the internet, and had no luck for a long time either googling this problem or reading about the readline() function in python—because I didn’t realize that the solution was to change how I was opening the file, not how I was using readline.  Hence the rare technical solution post by yours truly.

Filed under coding python