On Fri, Sep 4, 2015 at 1:48 PM, Ian Kelly <[email protected]> wrote:
> On Fri, Sep 4, 2015 at 1:11 PM, <[email protected]> wrote:
>> 6- "include" script statement (extending namespace to another script, like
>> PHP)
>
> def include(filename):
> exec(open(filename).read())
Sorry, that doesn't work because it takes locals from the include
function. You probably need something more like this:
def include(filename, globals):
exec(open(filename).read(), globals)
To be called like:
include("foo.py", globals())
If you want to get fancy you could probably have include inspect the
stack to pull the globals from the parent stack frame instead of
explicitly passing them in.
--
https://mail.python.org/mailman/listinfo/python-list