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

Discussion in 'Python' started by Daniel Ortmann, Jul 2, 2003.

  1. These problems only happen on Windows. On Linux everything works fine.
    Has anyone else run into these bugs? Any suggestions?

    Where do I find out the proper bug reporting process?


    Problem #1:

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

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

    Problem #2:

    While trying to fix up the first problem I run into another problem.
    The following string replace code works until right around the boundary
    at 2^7 * 1024, i.e. near 131072 (around line 1224), and then inserts a
    bunch of \x00's in the string!

    Before the \x00's, all of the \x0d's were correctly replaced. After the
    \x00's, NONE of them were replaced.

    content = file( fname, 'rb' ).read().replace( '\x0d', '' )
    file( fname, 'wb' ).write( content )

    Problem #3:

    The same problem also happens with the re module.

    content = re.sub( '\x0d', '', file( fname, 'rb' ).read() )
    file( fname, 'wb' ).write( content )

    --
    Daniel Ortmann, LSI Logic, 3425 40th Av NW, Suite 200, Rochester MN 55901
    work: / 507.535.3861 / 63861 int / 8012.3861 gdds
    home: / 507.288.7732, 2414 30Av NW #D, Rochester MN 55901
    Daniel Ortmann, Jul 2, 2003
    #1
    1. Advertising

  2. Daniel Ortmann

    Steve Holden Guest

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

    "Daniel Ortmann" <> wrote in message
    news:...
    > These problems only happen on Windows. On Linux everything works fine.
    > Has anyone else run into these bugs? Any suggestions?
    >
    > Where do I find out the proper bug reporting process?
    >


    http://sourceforge.net/tracker/?atid=105470&group_id=5470&func=browse

    regards
    --
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/pwp/
    Steve Holden, Jul 2, 2003
    #2
    1. Advertising

  3. 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
    Skip Montanaro, Jul 2, 2003
    #3
  4. Re: Python-2.3b1 bugs on Windows2000 with: the new csv module,string replace, and the re module

    Skip Montanaro <> writes:

    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 ) ) )

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

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

    Ok, that is the same work around that I used. Perhaps the documentation
    should say something about using binary mode?

    Or perhaps the DictWriter constructure should open the file in binary
    mode if given a string rather than a file object?

    How do we avoid people stumbling as I did?

    --
    Daniel Ortmann, LSI Logic, 3425 40th Av NW, Suite 200, Rochester MN 55901
    work: / 507.535.3861 / 63861 int / 8012.3861 gdds
    home: / 507.288.7732, 2414 30Av NW #D, Rochester MN 55901
    Daniel Ortmann, Jul 2, 2003
    #4
  5. Re: Python-2.3b1 bugs on Windows2000 with: the new csv module,string replace, and the re module

    Daniel> Perhaps the documentation should say something about using
    Daniel> binary mode?

    Good point. I'll fix the docs.

    Daniel> Or perhaps the DictWriter constructure should open the file in
    Daniel> binary mode if given a string rather than a file object?

    Nah, too much overloading going on.

    Skip
    Skip Montanaro, Jul 2, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raghunath
    Replies:
    0
    Views:
    472
    Raghunath
    Sep 15, 2003
  2. Elizabeth Harmon

    Windows2000,Word2003,ASP.Net - Help

    Elizabeth Harmon, Nov 30, 2003, in forum: ASP .Net
    Replies:
    10
    Views:
    554
    Elizabeth Harmon
    Dec 1, 2003
  3. Oleg Broytmann

    SQLObject 0.7.3b1

    Oleg Broytmann, Jan 22, 2007, in forum: Python
    Replies:
    0
    Views:
    219
    Oleg Broytmann
    Jan 22, 2007
  4. Andy \(ABA\)

    ASP WebClassRuntime and Windows2000 SP4 Problem

    Andy \(ABA\), Aug 28, 2003, in forum: ASP General
    Replies:
    0
    Views:
    167
    Andy \(ABA\)
    Aug 28, 2003
  5. Josef 'Jupp' Schugt

    Still use 'ruby-bugs' for Ruby bugs?

    Josef 'Jupp' Schugt, Nov 4, 2004, in forum: Ruby
    Replies:
    2
    Views:
    155
    Tom Copeland
    Nov 4, 2004
Loading...

Share This Page