Author vstinner
Recipients amaury.forgeotdarc, benjamin.peterson, brett.cannon, jmfauth, sjmachin, vstinner
Date 2009-03-25.15:23:15
SpamBayes Score 4.55417e-06
Marked as misclassified No
Message-id <>
In-reply-to <>
> Yes, I could, but I think this is not an IDLE issue
> (...)
>   File "", line 8, in <module>
>     ii.runsource(source)
>   (...)
>   File "c:\python30\lib\", 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
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