Abnormal \r characters inside a .csv text file raise
an error when the file is read by csv.reader() (Python
2.3).
I'm sending the following files:
test.txt : a "csv"-like text file with a \r
character;
test1.txt : same file, with an x replacing \r;
example.txt: the hard copy of my Python shell when
testing csv.reader() on former files.
I found this error when reading a many-mega, SAS
export csv file; I'm a Python beginner, and I found
hard to understand such an error and to find the three
abnormal \r characters inside!
This is a warning to newbies like me and a question
for experts: is it a bug into csv module?
___________________________________
Yahoo! Mail: gratis 1GB per i messaggi e allegati da 10MB
http://mail.yahoo.it
"first record","second record"
"third record","here abnormal
char"
"first record","second record"
"third record","here abnormal x char"
Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
****************************************************************
Personal firewall software may warn about the connection IDLE
makes to its subprocess using this computer's internal loopback
interface. This connection is not visible on any external
interface and no data is sent to or received from the Internet.
****************************************************************
IDLE 1.0 ==== No Subprocess ====
>>> import csv
>>> f=open("test.txt","rb") # the abnormal \r containig file
>>> f1=open("test1.txt","rb") # same file after replacing \r with x
>>> list(csv.reader(f))
Traceback (most recent call last):
File "<pyshell#4>", line 1, in ?
list(csv.reader(f))
Error: newline inside string
>>> list(csv.reader(f1))
[['first record', 'second record'], ['third record', 'here abnormal x char']]
>>>
_______________________________________________
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor