execfile and function call
gagsl-py2 at yahoo.com.ar
Tue Sep 25 03:43:40 CEST 2007
En Mon, 24 Sep 2007 16:59:52 -0300, Dave Westerman <dlwester at comcast.net>
> I've got a Jython script where I'm doing an execfile() to pull in a
> small script that contains a function, which I then call.
> optionList = createOptionList(applOptions)
> When I do this at the global level in my main script, it works just
> fine. However, when I move this code into a function in my main script,
> then it fails, telling me it can't find the function createOptionList().
> Traceback (innermost last):
> File "<string>", line 459, in ?
> File "<string>", line 429, in processApplication
> NameError: createOptionList
> Does anyone have any idea what I'm doing wrong? I noticed that
> createOptionList no longer shows up when I do a dir(). Do I somehow have
> to get that to be a global? How do I do that?
To answer your specific question: Use execfile(app_applscript, globals())
instead (see <http://docs.python.org/lib/built-in-funcs.html#l2h-26>)
But I think it would be better to *import* createOptionList from that
module. Using __import__ or imp may help, but the details are a bit
different in Jython so I can't help you so much in this regard.
More information about the Python-list