[issue1537721] csv module: add header row to DictWriter

2010-08-29 Thread florian-rathgeber

Changes by florian-rathgeber florian.rathge...@gmail.com:


--
nosy: +florian-rathgeber

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2010-03-05 Thread Dirkjan Ochtman

Dirkjan Ochtman dirk...@ochtman.nl added the comment:

Both the solaris and windows slaves seem to have succeeded this time.

--
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2010-03-04 Thread Florent Xicluna

Florent Xicluna florent.xicl...@gmail.com added the comment:

according to the buidbots, it hurts some platforms: Windows XP, Windows 7 and 
sparc Solaris10


 * sparc solaris10

test_writerows (test.test_csv.Test_Csv) ... ok

==
FAIL: test_write_simple_dict (test.test_csv.TestDictFields)
--
Traceback (most recent call last):
  File /home2/buildbot/slave/trunk.loewis-sun/build/Lib/test/test_csv.py, 
line 607, in test_write_simple_dict
self.assertEqual(fileobj.read(), 10,,abc\r\n)
AssertionError: 'f1,f2,f3\r\n' != '10,,abc\r\n'

--
Ran 84 tests in 17.335s

FAILED (failures=1)
test test_csv failed -- Traceback (most recent call last):
  File /home2/buildbot/slave/trunk.loewis-sun/build/Lib/test/test_csv.py, 
line 607, in test_write_simple_dict
self.assertEqual(fileobj.read(), 10,,abc\r\n)
AssertionError: 'f1,f2,f3\r\n' != '10,,abc\r\n'

 * x86 XP and x86 Windows7

test_csv
test test_csv failed -- Traceback (most recent call last):
  File 
D:\cygwin\home\db3l\buildarea\trunk.bolen-windows\build\lib\test\test_csv.py, 
line 604, in test_write_simple_dict
writer.writerow({f1: 10, f3: abc})
  File D:\cygwin\home\db3l\buildarea\trunk.bolen-windows\build\lib\csv.py, 
line 148, in writerow
return self.writer.writerow(self._dict_to_list(rowdict))
IOError: [Errno 0] Error

--
nosy: +flox

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2010-03-04 Thread Dirkjan Ochtman

Dirkjan Ochtman dirk...@ochtman.nl added the comment:

Testing on Windows with this:

Index: Lib/test/test_csv.py
===
--- Lib/test/test_csv.py(revision 78430)
+++ Lib/test/test_csv.py(working copy)
@@ -9,6 +9,7 @@
 import tempfile
 import csv
 import gc
+import io
 from test import test_support
 
 class Test_Csv(unittest.TestCase):
@@ -595,7 +596,7 @@
 ### short means there are fewer elements in the row than fieldnames
 def test_write_simple_dict(self):
 fd, name = tempfile.mkstemp()
-fileobj = os.fdopen(fd, w+b)
+fileobj = io.open(fd, 'w+b')
 try:
 writer = csv.DictWriter(fileobj, fieldnames = [f1, f2, f3])
 writer.writeheader()

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2010-03-04 Thread Dirkjan Ochtman

Dirkjan Ochtman dirk...@ochtman.nl added the comment:

Committed in r78660 after positive comment from briancurtin re Windows. 
Hopefully this fixes Solaris, as well.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2010-02-23 Thread Dirkjan Ochtman

Dirkjan Ochtman dirk...@ochtman.nl added the comment:

Fixed in SVN, r78384.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2010-02-23 Thread Dirkjan Ochtman

Changes by Dirkjan Ochtman dirk...@ochtman.nl:


--
assignee:  - djc
resolution:  - fixed
status: open - closed

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-12-07 Thread djc

djc dirk...@ochtman.nl added the comment:

I'd like to commit this, but it would be nice to get a review first:

Index: Lib/csv.py
===
--- Lib/csv.py  (revision 76697)
+++ Lib/csv.py  (working copy)
@@ -132,6 +132,10 @@
 self.extrasaction = extrasaction
 self.writer = writer(f, dialect, *args, **kwds)
 
+def writeheader(self):
+header = dict(zip(self.fieldnames, self.fieldnames))
+self.writerow(header)
+
 def _dict_to_list(self, rowdict):
 if self.extrasaction == raise:
 wrong_fields = [k for k in rowdict if k not in self.fieldnames]
Index: Lib/test/test_csv.py
===
--- Lib/test/test_csv.py(revision 76697)
+++ Lib/test/test_csv.py(working copy)
@@ -598,8 +598,10 @@
 fileobj = os.fdopen(fd, w+b)
 try:
 writer = csv.DictWriter(fileobj, fieldnames = [f1, f2,
f3])
+writer.writeheader()
 writer.writerow({f1: 10, f3: abc})
 fileobj.seek(0)
+self.assertEqual(fileobj.readline(), f1,f2,f3\r\n)
 self.assertEqual(fileobj.read(), 10,,abc\r\n)
 finally:
 fileobj.close()

(I think I have commit privileges already.)

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-12-07 Thread Skip Montanaro

Skip Montanaro s...@pobox.com added the comment:

I'm sorry, but I don't have time to look at this right now.  On the one
hand, one person asks for more symmetry.  Someone else wants to add a
writeheader method.  If you want symmetry shouldn't the DictWriter
simply write the header without being asked?  I'm confused by the
various options and feel that someone is going to be disappointed by any
solution.  For the time being at least I would prefer that the status
quo remain in place.

S

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-12-07 Thread djc

djc dirk...@ochtman.nl added the comment:

Skip, I agree that it's hard to decide if we should have the class write
the header on __init__(). I figured starting off with a method to make
doing it manually is a good start; people can start using that, and if
it's deemed useful we can always add the auto-write later.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-12-07 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

We can't change default behaviour because it will break compatibility,
so an additional method looks ok to me.

--
nosy: +pitrou
stage: test needed - patch review
versions: +Python 3.2 -Python 3.1

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-12-07 Thread Skip Montanaro

Skip Montanaro s...@pobox.com added the comment:

Antoine We can't change default behaviour because it will break
Antoine compatibility, so an additional method looks ok to me.

Why can't default behavior be changed?

S

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-12-07 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

Le lundi 07 décembre 2009 à 23:42 +, Skip Montanaro a écrit :
 Skip Montanaro s...@pobox.com added the comment:
 
 Antoine We can't change default behaviour because it will break
 Antoine compatibility, so an additional method looks ok to me.
 
 Why can't default behavior be changed?

Well, because it will break assumptions about the generated documents?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-12-07 Thread Skip Montanaro

Skip Montanaro s...@pobox.com added the comment:

Antoine We can't change default behaviour because it will break
Antoine compatibility, so an additional method looks ok to me.

 Why can't default behavior be changed?

Antoine Well, because it will break assumptions about the generated 
documents?

Isn't the alpha period (2.7 and 3.2 in this case) precisely when an API can
change?

Skip

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-12-07 Thread Antoine Pitrou

Antoine Pitrou pit...@free.fr added the comment:

 Isn't the alpha period (2.7 and 3.2 in this case) precisely when an API can
 change?

Well, it can, but only if there are compelling reasons to do so. It
should be the exception rather than the rule.
The reasons here seem far from compelling, and moreover we can't detect
whether the user is expecting the new or the old behaviour.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-12-07 Thread Skip Montanaro

Skip Montanaro s...@pobox.com added the comment:

 Isn't the alpha period (2.7 and 3.2 in this case) precisely when an
 API can change?

Antoine Well, it can, but only if there are compelling reasons to do
Antoine so. It should be the exception rather than the rule.  The
Antoine reasons here seem far from compelling, and moreover we can't
Antoine detect whether the user is expecting the new or the old
Antoine behaviour.

Fine.  Dirkjan, assuming there are the necessary test cases and
documentation changes, feel free to check in your patch and close the
ticket.

Skip

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-08-06 Thread djc

Changes by djc dirk...@ochtman.nl:


--
nosy: +djc

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-04-18 Thread Matthew Iversen

Matthew Iversen teh@gmail.com added the comment:

Skip, you were arguing in another csv issue on a NamedTupleReader that
the Reader and Writer should work in concert together.

Certainly, making this default functionality for DictWriter would
definitely make it work more in concert with DictReader.

A sample process of reading and writing might be:

1. DictReader reads in header names, reads in data
2. Pass in header names to DictWriter on init
3. DictWriter writes out modified data back to csv file (headers get
written automatically or with a method call)
4. DictReader can now reader in the csv file automatically again with
header names

My feeling is, if DictReader can read in head names, why can't
DictWriter write them back out again? Shouldn't there be a good amount
of symmatry to their function/abilities?

My feeling of how to implement this functionality would be to include a
new init argument, say 'writeheader'. It's default would be True if you
wanted to implement this new feature by default, or False if you wanted
to keep it an option so that older scripts relying on the old
functionality won't break immmediately.
DictWriter would then write the header on the first call to writerow(s),
or perhaps also with an explicit call to writeheader() say.

I certainly am miffed by the fact that DictWriter cannot produce
(normally) a csv file that DictReader can read in automatically.

--
nosy: +ivo

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-03-31 Thread Skip Montanaro

Skip Montanaro s...@pobox.com added the comment:

I don't see a patch.  Is there some reason that if you need this
you can't simply subclass DictWriter?

--
nosy: +skip.montanaro

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1537721] csv module: add header row to DictWriter

2009-03-29 Thread Daniel Diniz

Changes by Daniel Diniz aja...@gmail.com:


--
keywords: +patch
stage:  - test needed
versions: +Python 2.7, Python 3.1

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue1537721
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com