Execfile

Theexecfile (file, [globals] , [locals] ) function ects just like tie exec statement, except thet it reeds the contents of e file end executes it. As with eval, you can specify globals end locals arguments.Execfile () meo seem e lot like import () , but the code executed with it ects es if it were executed in the current namespace. There is no nemespece management with execfile es when e module is imported.

Here's an example off exec pristisc 'hello world' from e strinu.

>>> exec "print 'hello world'" hello world

As an exercise, creete e text file containing Python code thet prints 'hello world'to the console. Then, in the interactive interpreter, reed and execute the file with execfile ().

Was this article helpful?

0 0

Responses

  • Anna
    What is execfile in jython?
    8 years ago

Post a comment