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.
--
Ticket URL: <https://code.djangoproject.com/ticket/34642>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by liori):
I am willing to work in this feature, I'd like to just know whether it be
considered for addition to the project?
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:1>
* status: new => closed
* resolution: => wontfix
Comment:
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:2>
* easy: 0 => 1
* stage: Unreviewed => Accepted
Comment:
Reopening and accepting since there seems to be a consensus in the
[https://forum.djangoproject.com/t/file-open-to-support-different-
encodings/21491 developer forum].
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:3>
* status: closed => new
* resolution: wontfix =>
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:4>
Comment (by SecondPort):
i will work on this
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:5>
* owner: nobody => SecondPort
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
* status: new => assigned
* needs_tests: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:6>
Comment (by abdulrahman):
Hey,
I can take this ticket if no one has time for it, I had to use
io.TextIOWrapper to use a different encoding.
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:7>
* owner: SecondPort => (none)
* status: assigned => new
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:8>
Comment (by Yves Weissig):
If there are no other takers I'm happy to clean up the patch and write
tests.
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:9>
Comment (by Mariusz Felisiak):
Replying to [comment:9 Yves Weissig]:
> If there are no other takers I'm happy to clean up the patch and write
tests.
Thanks, please do.
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:10>
* owner: (none) => Yves Weissig
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:11>
Comment (by Yves Weissig):
Just a quick update, I'm on it, PR will follow shortly.
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:12>
Comment (by Yves Weissig):
The PR is now ready [https://github.com/django/django/pull/17173 here].
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:13>
* needs_better_patch: 1 => 0
* needs_tests: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:14>
* needs_docs: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:15>
* needs_docs: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:16>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"369b498219be791ebec8233208f08f07621b8359" 369b4982]:
{{{
#!CommitTicketReference repository=""
revision="369b498219be791ebec8233208f08f07621b8359"
Fixed #34642 -- Added File.open() support for *args and **kwargs.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/34642#comment:17>