Issue 34713: csvwriter.writerow()'s return type is undocumented (original) (raw)

Issue34713

Created on 2018-09-17 17:14 by nchammas, last changed 2022-04-11 14:59 by admin.

Messages (5)
msg325557 - (view) Author: Nicholas Chammas (nchammas) * Date: 2018-09-17 17:14
It _looks_ like csvwriter.writerow() returns the number of bytes (or is it characters?) written. However, there is no documentation of this: https://docs.python.org/3.7/library/csv.html#csv.csvwriter.writerow Is this behavior part of the method's "contract"? And if so, shouldn't we document it? The same goes for csvwriter.writerows().
msg325559 - (view) Author: Nicholas Chammas (nchammas) * Date: 2018-09-17 17:20
Looks like it's bytes written, not characters: ``` >>> import csv >>> with open('test.csv', 'w', newline='') as csv_file: ... csv_writer = csv.writer( ... csv_file, ... dialect='unix', ... ) ... csv_writer.writerow('야 너') # 3 characters ... 12 ```
msg337776 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2019-03-12 16:43
csvwriter.writerows() does not return anything. The return value of csv.writecsv() is the return value of the write() method of the file object given as parameter in csv.writer(). I'm not sure it's safe to document it, should we return None instead?
msg337840 - (view) Author: Rémi Lapeyre (remi.lapeyre) * Date: 2019-03-13 10:11
Issue #27497 is related, it adds documentation a return value and documentation to csv.DictWriter.writeheader which uses writerow internally. In the discussion, @lsowen found code that uses it at https://docs.djangoproject.com/en/1.9/howto/outputting-csv/#streaming-large-csv-files. Given that this behavior has been added to csv.DictWriter.writeheader it makes sense to document csv.Writer.writerow. Do you want to post a pull request?
msg337866 - (view) Author: Nicholas Chammas (nchammas) * Date: 2019-03-13 17:09
Nope, go ahead.
History
Date User Action Args
2022-04-11 14:59:06 admin set github: 78894
2019-03-13 17:09:31 nchammas set messages: +
2019-03-13 10:11:40 remi.lapeyre set messages: +
2019-03-12 16:43:29 remi.lapeyre set nosy: + remi.lapeyremessages: +
2018-09-17 18:33:27 xtreak set nosy: + xtreak
2018-09-17 17:20:27 nchammas set messages: +
2018-09-17 17:14:05 nchammas create