global myfunc; def myfunc():

Bruce Dodson bruce_dodson at bigfoot.com
Thu Jul 29 13:27:51 EDT 1999


Thanks.  Actually, the embedding interface also has a Python.ExecGlobal
method
which binds everything to __main__, so the recommended way of binding a
function to the global namespace is Python.ExecGlobal("import modulename").
I think I will say in the documentation that you can use the python global
statement
to bind specific global variables, or you can use ExecGlobal to make
everything
global.  Then I will say that the global statement is the recommended way
for
variables, whereas ExecGlobal is recommended for defining functions.  Users
can draw the conclusion that recommendations are not requirements, but I
won't spell it out for them. :-)


-----Original Message-----
From: Gordon McMillan <gmcm at hypernet.com>
To: Bruce Dodson <bruce_dodson at bigfoot.com>; python-list at python.org
<python-list at python.org>
Date: Thursday, July 29, 1999 8:23 AM
Subject: Re: global myfunc; def myfunc():


Bruce Dodson wrote:

> I have noticed that, when using python as an embedded language in
> another program, using a temporary dictionary for a private
> namespace, and using __main__'s dictionary for my global namespace,
> I can say:
>
> global myfunc
> def myfunc():
>   ...
>
> to bind myfunc into the global namespace, which allows it to persist
> across calls.  But I want to make sure that is "intended behavior"
> and not just some implementation quirk, so I can decide whether to
> document that as a feature.

It may be an unusual use, but there's nothing quirky about the
mechanism being used. You're safe.

- Gordon






More information about the Python-list mailing list