473,473 Members | 1,875 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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: Da************@lsil.com / 507.535.3861 / 63861 int / 8012.3861 gdds
home: or*****@isl.net / 507.288.7732, 2414 30Av NW #D, Rochester MN 55901
Jul 18 '05 #1
7 2302
"Daniel Ortmann" <do******@lsil.com> wrote in message
news:hc*************@mhbs.lsil.com...
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/

Jul 18 '05 #2

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

Jul 18 '05 #3

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

Jul 18 '05 #4
Skip Montanaro <sk**@pobox.com> 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: Da************@lsil.com / 507.535.3861 / 63861 int / 8012.3861 gdds
home: or*****@isl.net / 507.288.7732, 2414 30Av NW #D, Rochester MN 55901

Jul 18 '05 #5

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

Jul 18 '05 #6

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

Jul 18 '05 #7
Skip Montanaro <sk**@pobox.com> 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: Da************@lsil.com / 507.535.3861 / 63861 int / 8012.3861 gdds
home: or*****@isl.net / 507.288.7732, 2414 30Av NW #D, Rochester MN 55901

Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Olaf Meyer | last post by:
I'm having some problems compiling Python 2.3.3 on HP-UX (B.11.00). I've tried sevral different options for the configure script (e.g. enabling/disabling gcc, aCC) but I always get the same problem...
9
by: kbass | last post by:
I am starting to learn Python but I want to know how the job market looks for programming using Python. I really don't see many jobs (probably one or two) that require Python experience at all....
5
by: paolo veronelli | last post by:
I've a vague idea of the differences,I don't know scheme anyway. I'd like to see an example to show what is missing in python about closures and possibly understand if ruby is better in this...
1
by: Sean | last post by:
Hi, Trying to compile the PythonCE (Validus Medical Systems Python 2.3.4) using eVC++ 4.0 and the Smartphone2003 SDK. Linking is generating 28 errors. I dug into the first one (PyErr_Fetch)...
4
by: Edmond Rusjan | last post by:
Hi All, I'd like to use Python-2.3.4 on OSF1 V4.0, but have trouble installing. With a plain "./configure; make" build, I cannot import socket. If I uncomment the socketmodule in Modules/Setup,...
3
by: Saravanan | last post by:
Hello, Im running Python Application as a Windows Service (using windows extensions). But, sporadically the application crashes (crash in Python23.dll) and this stops the service. This...
9
by: John Dean | last post by:
Hi Does anybody know from where I can get a copy of the source for Python V2.4.2. I downloaded what is reckoned to be the source code from www.python.org, but is turns out to be the MacXOS...
11
by: Osiris | last post by:
I have these pieces of C-code (NOT C++ !!) I want to call from Python. I found Boost. I have MS Visual Studio 2005 with C++. is this the idea: I write the following C source file:...
6
by: E-Lo | last post by:
Is there any other edition of Python for Palm OS instead of Pippy?
0
by: Tim Spens | last post by:
--- On Fri, 6/27/08, Tim Spens <t_spens@yahoo.comwrote: I think I know where the problem is but I'm unsure how to fix it. When I call Register_Handler(...) from python via...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.