Opened 19 months ago
Closed 16 months ago
#34642 closed New feature (fixed)
File.open to support different encodings
Reported by: | Tomasz Melcer | Owned by: | Yves Weissig |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
Currently the File.open method has only a single parameter mode
. mode
can suggest opening a file in text mode. Then, Python's open
will by default attempt to use the common utf-8 encoding.
It is a common pattern in a code base I work on to use the utf-8-sig
encoding for CSV files, as this provides a slight improvement to user experience when opening the file in Excel. Right now, to create a file in this encoding using Django's File, we have to open it in a binary mode and explicitly wrap the file handle in a codec. It would be helpful if, just like the base Python's open
function, File.open
also accepted an encoding
parameter, and pass it to the Python's open
function.
Change History (17)
comment:1 by , 19 months ago
comment:2 by , 19 months ago
Resolution: | → wontfix |
---|---|
Status: | new → closed |
Hi Tomasz,
Sounds like a good idea, though…
Not many people will see feature requests on the issue tracker so people are encouraged to start discussion in the Django forum first: https://code.djangoproject.com/wiki/DevelopersMailingList. This way more people will see the request & respond. One thing that comes to mind is that the File
class could pass through *args, **kwargs
to the open()
function to avoid gatekeeping, though not sure whether this was intentional or not 🤔
The procedure is to close the ticket as "wontfix" pending further discussion on the forum, we can reopen when a decision is made to proceed.
comment:3 by , 18 months ago
Easy pickings: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
Reopening and accepting since there seems to be a consensus in the developer forum.
comment:4 by , 18 months ago
Resolution: | wontfix |
---|---|
Status: | closed → new |
comment:6 by , 18 months ago
Has patch: | set |
---|---|
Needs tests: | set |
Owner: | changed from | to
Patch needs improvement: | set |
Status: | new → assigned |
comment:7 by , 18 months ago
Hey,
I can take this ticket if no one has time for it, I had to use io.TextIOWrapper to use a different encoding.
comment:8 by , 17 months ago
Owner: | removed |
---|---|
Status: | assigned → new |
follow-up: 10 comment:9 by , 17 months ago
If there are no other takers I'm happy to clean up the patch and write tests.
comment:10 by , 17 months ago
Replying to Yves Weissig:
If there are no other takers I'm happy to clean up the patch and write tests.
Thanks, please do.
comment:11 by , 17 months ago
Owner: | set to |
---|---|
Status: | new → assigned |
comment:14 by , 16 months ago
Needs tests: | unset |
---|---|
Patch needs improvement: | unset |
comment:15 by , 16 months ago
Needs documentation: | set |
---|
comment:16 by , 16 months ago
Needs documentation: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
I am willing to work in this feature, I'd like to just know whether it be considered for addition to the project?