execfile and function call

D

Dave Westerman

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.

execfile(app_applscript)
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?
 
T

timaranz

I'm not sure why it doesn't work, but a better way would be to use the
import statement:

import app_applscrip
app_applscript.createOptionList(applOptions)

Cheers
Tim
 
G

Gabriel Genellina

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.

execfile(app_applscript)
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top