Conversion: execfile --> exec

MRAB python at mrabarnett.plus.com
Mon Jun 13 10:11:07 EDT 2016


On 2016-06-13 14:24, Long Yang wrote:
> The python 2.x command is as following:
> ---------------------------
> info = {}
> execfile(join('chaco', '__init__.py'), info)
> ------------------------------
>
> But execfile has been removed in python 3.x.
> So my problem is how to convert the above to a 3.x based command?
>
> thanks very much
>
Open the file and pass it to exec:

info = {}
with open(join('chaco', '__init__.py')) as file:
     exec(file.read(), info)




More information about the Python-list mailing list