"Currall, Andrew" <andrew.curr...@aecom.com> wrote

DemandModel.py is a valid, working python script. If I create another script file, then:

execfile('DemandModel.py')

You probably shouldn't. You should probably be importing it. Is there a reason why you want to use execfile()? Its nearly always the wrong solution...

def runfile():
    execfile('DemandModel.py')

runfile()

  File "DemandModel.py", line 12, in DemandModel
    Parameters=ReadDmData(segname)
NameError: global name 'ReadDmData' is not defined

So it works on a line by itself but not in a function?
And it is running the file but getting an undefined name. odd.
What happens if you run execfile() from a new interpreter prompt?

CodeFile=open('DemandModel.py', 'r')
exec(CodeFile)

What happens if you use import (assuming you store in somewhere in sys.path...)


--
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/


_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to