This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients amaury.forgeotdarc, benjamin.peterson, brett.cannon, jmfauth, sjmachin, vstinner
Date 2009-03-25.15:23:15
SpamBayes Score 4.554174e-06
Marked as misclassified No
Message-id <200903251622.02527.victor.stinner@haypocalc.com>
In-reply-to <1237993010.71.0.488597004993.issue4626@psf.upfronthosting.co.za>
Content
> 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
History
Date User Action Args
2009-03-25 15:23:19vstinnersetrecipients: + vstinner, brett.cannon, sjmachin, amaury.forgeotdarc, benjamin.peterson, jmfauth
2009-03-25 15:23:16vstinnerlinkissue4626 messages
2009-03-25 15:23:15vstinnercreate