[issue4626] compile() doesn't ignore the source encoding when a string is passed in
STINNER Victor
report at bugs.python.org
Wed Mar 25 16:23:18 CET 2009
STINNER Victor <victor.stinner at haypocalc.com> added the comment:
> Yes, I could, but I think this is not an IDLE issue
> (...)
> File "uuu.py", line 8, in <module>
> ii.runsource(source)
> (...)
> File "c:\python30\lib\codeop.py", line 70, in _maybe_compile
> for line in source.split("\n"):
> TypeError: Type str doesn't support the buffer API
compile() works as expected. Your problem is related to
InteractiveInterpreter().runsource(source) which is part of IDLE. runsource()
is not compatible with bytes, only 'str' type is accepted.
The error comes from bytes.split(str): _maybe_compile() should use
source.split(b'\n') if source type is bytes. Or runsource() should reject
bytes directly.
> source = str(source, 'cp1252') #<<<<<<<<<<
> ii.runsource(source)
>
> Output: (ok)
Yes, runsource() (only) works with the str type.
> I suspect the miscellaneous discussions one finds from people attempting
> to write a "correct" execfile() for Python 3 are coming from this.
Please see issues:
- issue #5524: execfile() removed from Python3
- issue #4628: No universal newline support for compile() when using bytes
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4626>
_______________________________________
More information about the Python-bugs-list
mailing list