<div dir="ltr"><div>This situation is a bit different from coding cookies. They are used when we have bytes from a source file, but we don't know its encoding. During interactive session the tokenizer always knows the encoding of the bytes. I would think that in the case of interactive session the PyCF_SOURCE_IS_UTF8 should be always set so the bytes containing encoded non-ASCII characters are interpreted correctly. Why I'm talking about PyCF_SOURCE_IS_UTF8? eval(u"u'\u03b1'") -> u'\u03b1' but eval(u"u'\u03b1'".encode('utf-8')) -> u'\xce\xb1'. I understand that in the second case eval has no idea how are the given bytes encoded. But the first case is actually implemented by encoding to utf-8 and setting PyCF_SOURCE_IS_UTF8. That's why I'm talking about the flag.<br><br></div>Regards, Drekin<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Apr 29, 2015 at 9:25 AM, Nick Coghlan <span dir="ltr"><<a href="mailto:ncoghlan@gmail.com" target="_blank">ncoghlan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 29 April 2015 at 06:20, Adam Bartoš <<a href="mailto:drekin@gmail.com">drekin@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> is it possible to somehow tell Python 2.7 to compile a code entered in the<br>
> interactive session with the flag PyCF_SOURCE_IS_UTF8 set? I'm considering<br>
> adding support for Python 2 in my package<br>
> (<a href="https://github.com/Drekin/win-unicode-console" target="_blank">https://github.com/Drekin/win-unicode-console</a>) and I have run into the fact<br>
> that when u"α" is entered in the interactive session, it results in<br>
> u"\xce\xb1" rather than u"\u03b1". As this seems to be a highly specialized<br>
> question, I'm asking it here.<br>
<br>
</div></div>As far as I am aware, we don't have the equivalent of a "coding<br>
cookie" for the interactive interpreter, so if anyone else knows how<br>
to do it, I'll be learning something too :)<br>
<br>
Cheers,<br>
Nick.<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Nick Coghlan | <a href="mailto:ncoghlan@gmail.com">ncoghlan@gmail.com</a> | Brisbane, Australia<br>
</font></span></blockquote></div><br></div>