[Python-ideas] duck typing for io write methods

Andrew Barnert abarnert at yahoo.com
Sun Jun 16 00:19:42 CEST 2013


On Jun 15, 2013, at 10:12, Paul Moore <p.f.moore at gmail.com> wrote:

> On 15 June 2013 17:51, Wolfgang Maier <wolfgang.maier at biologie.uni-freiburg.de> wrote:
>> So if I understand the PEP correctly, then, theoretically, text mode file IO
>> objects could be implemented to declare that all they'll ever need is 1 byte
>> strings (if the encoding is ASCII-compatible)?
> 
> There's no need to "declare" anything - if the file does not contain code points outside the 1-byte range, it just works. No declaration needed.
> 
> The changes in the PEP are entirely transparent to the user, they just magically make your code faster if possible :-)

Of course if you want to _ensure_ that you're getting the optimization, just specify encoding='ascii' when opening the file. Then, instead of slowing down or wasting space, it will raise an exception, which you can deal with as you see fit.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130615/1ba6492b/attachment-0001.html>


More information about the Python-ideas mailing list