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='i gnore' )
csvwriter.write row( 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().replac e( '\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 7 2315
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='i gnore' )
Daniel> csvwriter.write row( 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='i gnore' )
csvwriter.write row( dict( zip( infieldnames, infieldnames ) ) )
Skip
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 <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='i gnore' )
Daniel> csvwriter.write row( 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='i gnore' )
Skip> csvwriter.write row( 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
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='i gnore' )
Daniel> csvwriter.write row( 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='i gnore' )
csvwriter.write row( dict( zip( infieldnames, infieldnames ) ) )
Skip
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 <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='i gnore' )
Daniel> csvwriter.write row( 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='i gnore' )
Skip> csvwriter.write row( 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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 during
the final linking stage. Several PyThread_* symbols are undefined (for
details see the output below).
In order to get DCOracle2 support working I've also set the LDFLAGS
environment variable to "-lpthread -lcl" (as mentioned in the...
|
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. Most DBA and SA positions that I
have seen require Perl and most development position require Java or C++ so
how can learning Python benefit my career if there are little to no chance
that an employer will require the use of Python or consider using...
|
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 sense.
Iuse ruby and python in parallel for my job just to learn them and their
differences and python is shorter and cleaner ,but i feel it's missing
something,
in closures.Any hints?
|
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) and it's in pyerrors.h
so I don't see why it misses it.
Anyone have an idea?
TIA
|
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, the build fails.
Using gcc 3.4.2. Had no problem on OSF1 V5.1, Linux and Sun.
Have not been able to find reference to a similar problem in
comp.lang.python.
| |
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 problem cann't be
reproduced easily in my system and the call stack generated by the
application is given below. Please note that the call stack generation
is taken from crash dump file.
|
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 version with the core
modules missing. The reason I am looking for the source code is so I can
make a debug build
--
Best Regards
|
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:
============================
#include <iostream>
#include <stdafx.h>
|
by: E-Lo |
last post by:
Is there any other edition of Python for Palm OS instead of Pippy?
|
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 callback.setHandler1(callback1) this only seems to affect pythons ability to trigger an "event" in c. PyObject *Handler is always NULL even after I call Register_Handler(...). I thought there was some magic here that was assigning the pointer *Handler to my python...
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |