Python 3: exec arg 1
Alan G Isaac
alan.isaac at gmail.com
Sat Jan 17 14:12:45 EST 2009
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?
Thanks,
Alan Isaac
More information about the Python-list
mailing list