Python-2.3b1 bugs on Windows2000 with: the new csv module, string replace, and the re module

Skip Montanaro skip at pobox.com
Wed Jul 2 10:00:09 EDT 2003


    Daniel> Problem #1:

    Daniel> While using the csv module's DictWriter on MSDOS
    Daniel> (a.k.a. Windows2000), the output files get newlines like
    Daniel> \x0d\x0d\x0a instead of \x0d\x0a.

    Daniel> csvwriter = csv.DictWriter( file( out1filename, 'w' ), infieldnames, extrasaction='ignore' )
    Daniel> csvwriter.writerow( dict( zip( infieldnames, infieldnames ) ) )

CSV files are not really plain text files.  The line terminator string is an
explicit property of the file.  For example, you might want to write a CSV
file on a Windows 2000 machine which you intend to read on a Mac OS9 system
(where the line terminator is just \r).  You need to open CSV files with the
'b' flag.  This should work for you:

    csvwriter = csv.DictWriter( file( out1filename, 'wb' ), infieldnames,
                                extrasaction='ignore' )
    csvwriter.writerow( dict( zip( infieldnames, infieldnames ) ) )

Skip





More information about the Python-list mailing list