[ python-Bugs-1744580 ] cvs.get_dialect() return a class object
SourceForge.net
noreply at sourceforge.net
Thu Jun 28 13:41:39 CEST 2007
Bugs item #1744580, was opened at 2007-06-28 13:36
Message generated for change (Comment added) made by andrewmcnamara
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1744580&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Christian Kristukat (ckkart)
Assigned to: Andrew McNamara (andrewmcnamara)
Summary: cvs.get_dialect() return a class object
Initial Comment:
With python2.5 (and 2.6) cvs.get_dialect('excel') returns a Dialect class object in contrast to python 2.4 where an instance of csv.excel is returned, the former having only read only attributes.
% python2.4
Python 2.4.1 (#3, Jul 28 2005, 22:08:40)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1671)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import csv
>>> d = csv.get_dialect("excel")
>>> d
<csv.excel instance at 0x3ae058>
% python
Python 2.6a0 (trunk:54264M, Mar 10 2007, 15:19:48)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import csv
>>> d = csv.get_dialect("excel")
>>> d
<_csv.Dialect object at 0x137fac0>
----------------------------------------------------------------------
>Comment By: Andrew McNamara (andrewmcnamara)
Date: 2007-06-28 21:41
Message:
Logged In: YES
user_id=698599
Originator: NO
I should also mention that if you simply wanted a reader of a variant of
the "excel" dialect, the simplest way to achieve that is:
r=csv.reader(f, dialect='excel', delimiter='\t')
----------------------------------------------------------------------
Comment By: Andrew McNamara (andrewmcnamara)
Date: 2007-06-28 21:35
Message:
Logged In: YES
user_id=698599
Originator: NO
Dialects were made immutable, because they can potentially represent the
configuration of a running state machine (the reader), and the dialects are
potentially shared.
If you want to change a registered dialect, I suggest you do something
like:
csv.register_dialect('excel', csv.get_dialect('excel'),
delimiter='\t')
This changes the dialect for new users, but doesn't disrupt the state of
already running readers.
----------------------------------------------------------------------
Comment By: Skip Montanaro (montanaro)
Date: 2007-06-28 20:56
Message:
Logged In: YES
user_id=44345
Originator: NO
I took a brief look at the code. get_dialect is imported from the
underlying _csv.c extension module and didn't change between 2.4 and 2.5.
There is a new static function, _call_dialect, though. It is called from
several places, most notably from csv_register_dialect. The code in 2.4
that it replaces seems much different to me than the code in the body of
_call_dialect. I suspect there was some sort of regression there.
Assigning to Andrew since he's the primary author of the code as well as
the author of this particular change.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1744580&group_id=5470
More information about the Python-bugs-list
mailing list