Python 3: exec arg 1

Terry Reedy tjreedy at
Sat Jan 17 22:20:49 CET 2009

Alan G Isaac wrote:
> In Python 3, you can no longer ``exec(open(filename))``.
> I guess the reason is that in 3.0 ``open`` returns a stream,
> instead of open file, and exec wants
> "a string, bytes, or code object" and not a "TextIOWrapper".
> So it returns an error.
> Is it intentional that ``exec`` cannot handle a TextIOWrapper?
> Bottom line: has ``execfile(filename)`` really become
> ``exec(open(filename).read())``? Is this a good thing?

Yes. Yes.

More information about the Python-list mailing list