Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python-2.3b1 bugs on Windows2000 with: the new csv module, stringreplace, and the re module

Reply
Thread Tools

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

 
 
Daniel Ortmann
Guest
Posts: n/a
 
      07-01-2003
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: http://www.velocityreviews.com/forums/(E-Mail Removed) / 507.535.3861 / 63861 int / 8012.3861 gdds
home: (E-Mail Removed) / 507.288.7732, 2414 30Av NW #D, Rochester MN 55901
 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      07-02-2003
"Daniel Ortmann" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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...70&func=browse

regards
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/



 
Reply With Quote
 
 
 
 
Skip Montanaro
Guest
Posts: n/a
 
      07-02-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

 
Reply With Quote
 
Daniel Ortmann
Guest
Posts: n/a
 
      07-02-2003
Skip Montanaro <(E-Mail Removed)> 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: (E-Mail Removed) / 507.535.3861 / 63861 int / 8012.3861 gdds
home: (E-Mail Removed) / 507.288.7732, 2414 30Av NW #D, Rochester MN 55901

 
Reply With Quote
 
Skip Montanaro
Guest
Posts: n/a
 
      07-02-2003

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
read and write csv file using csv module jliu66 Python 0 10-19-2007 03:12 PM
Bugs and Bugs...get rid of them Jason Computer Security 1 01-31-2006 10:47 PM
Still use 'ruby-bugs' for Ruby bugs? Josef 'Jupp' Schugt Ruby 2 11-04-2004 10:10 PM
Windows2000 and Thumbnails Taishi Computer Support 0 06-26-2004 08:44 PM
csv bugs Magnus Lie Hetland Python 2 03-03-2004 08:54 PM



Advertisments