How to run script from interpreter?
Mikael Olofsson
mikael at isy.liu.se
Fri Jan 19 06:52:16 EST 2001
On 19-Jan-01 Dan Rolander wrote:
> This doesn't work for me. I know how to import and how to use the if
> __name__ trick, but how can I execute a script from the interactive Python
> interpreter? That is, can I load a script and have it run from inside the
> interpreter? (I'm sure this is easy I'm just not seeing it.)
Let's see... I think it was here somewhere... Ah, yes: In Python Library
Reference, 2.3 Built-in Functions, at
http://www.python.org/doc/current/lib/built-in-funcs.html
execfile (file[, globals[, locals]])
This function is similar to the exec statement, but parses a file
instead of a string. It is different from the import statement in
that it does not use the module administration -- it reads the file
unconditionally and does not create a new module.2.8
The arguments are a file name and two optional dictionaries. The
file is parsed and evaluated as a sequence of Python statements
(similarly to a module) using the globals and locals dictionaries
as global and local namespace. If the locals dictionary is omitted
it defaults to the globals dictionary. If both dictionaries are
omitted, the expression is executed in the environment where
execfile() is called. The return value is None.
HTH
/Mikael
-----------------------------------------------------------------------
E-Mail: Mikael Olofsson <mikael at isy.liu.se>
WWW: http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone: +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date: 19-Jan-01
Time: 12:35:02
/"\
\ / ASCII Ribbon Campaign
X Against HTML Mail
/ \
This message was sent by XF-Mail.
-----------------------------------------------------------------------
More information about the Python-list
mailing list