Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fileobj property to csv reader and writer objects #77339

Closed
samwyse mannequin opened this issue Mar 27, 2018 · 2 comments
Closed

Add fileobj property to csv reader and writer objects #77339

samwyse mannequin opened this issue Mar 27, 2018 · 2 comments
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@samwyse
Copy link
Mannequin

samwyse mannequin commented Mar 27, 2018

BPO 33158
Nosy @serhiy-storchaka

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2021-11-21.17:57:37.678>
created_at = <Date 2018-03-27.16:17:09.680>
labels = ['3.8', 'type-feature', 'library']
title = 'Add fileobj property to csv reader and writer objects'
updated_at = <Date 2021-11-21.17:57:37.677>
user = 'https://bugs.python.org/samwyse'

bugs.python.org fields:

activity = <Date 2021-11-21.17:57:37.677>
actor = 'iritkatriel'
assignee = 'none'
closed = True
closed_date = <Date 2021-11-21.17:57:37.678>
closer = 'iritkatriel'
components = ['Library (Lib)']
creation = <Date 2018-03-27.16:17:09.680>
creator = 'samwyse'
dependencies = []
files = []
hgrepos = []
issue_num = 33158
keywords = []
message_count = 2.0
messages = ['314538', '314541']
nosy_count = 2.0
nosy_names = ['samwyse', 'serhiy.storchaka']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue33158'
versions = ['Python 3.8']

@samwyse
Copy link
Mannequin Author

samwyse mannequin commented Mar 27, 2018

Many objects have properties that allow access to the arguments used to create them. In particular, file objects have a name property that returns the name used when opening a file. A fileobj property would be convenient, as you otherwise, for example, need to pass an extra argument to routines that need both the csv object and the underlying file object. Adopting this enhancement would also provide consistency with the dialect constructer argument, which is available as an object property.

Changing the fileobj while the csv object is in use would open a can of worms, so this should be a read-only property.

Optionally, the fileobj property could be reflected in the DictReader and DictWriter classes, but the value would be accessible via the .reader and .writer properties of those classes.

@samwyse samwyse mannequin added 3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement labels Mar 27, 2018
@serhiy-storchaka
Copy link
Member

A fileobj property would be convenient, as you otherwise, for example, need to pass an extra argument to routines that need both the csv object and the underlying file object.

But you should already have this object for creating csv.reader() or csv.writer().

Even if keep the argument of the constructor as an instance attribute, there is a problem with naming this attribute. csv.reader works not only with files. It accepts arbitrary iterable.

>>> it = iter(['Spam, Spam, Spam, Spam, Spam, Baked Beans', 'Spam, Lovely Spam, Wonderful Spam'])
>>> list(csv.reader(it))
[['Spam', ' Spam', ' Spam', ' Spam', ' Spam', ' Baked Beans'], ['Spam', ' Lovely Spam', ' Wonderful Spam']]

The dialect property is not a copy of the dialect constructer argument.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.8 only security fixes stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants