Re: function namespaces

2005-03-08 Thread Steve Holden
Darren Dale wrote: Generally, I avoid execfile within a function. What's your use case? There may be a better way to approach this problem... I am writing a simulation that loads some predefined constants, depending on the options called by the user. I originally had it set up to parse the file,

Re: function namespaces

2005-03-08 Thread Darren Dale
> Generally, I avoid execfile within a function. What's your use case? > There may be a better way to approach this problem... I am writing a simulation that loads some predefined constants, depending on the options called by the user. I originally had it set up to parse the file, and load the c

Re: function namespaces

2005-03-08 Thread Steven Bethard
Darren Dale wrote: Hi, I have a variable saved in a file like this #contents of myfile.py: testvar = [1,2,3,4] and I am trying to write a function that does something like this: def myfunction(filename): execfile(filename) print testvar The problem I am running into is that the glob

Re: function namespaces

2005-03-08 Thread M.E.Farmer
Hello Darren, I am not sure why you are using execfile(). Py> help(execfile) Help on built-in function execfile: execfile(...) execfile(filename[, globals[, locals]]) Read and execute a Python script from a file. The globals and locals are dictionaries, defaulting to the current g

Re: function namespaces

2005-03-08 Thread Max Erickson
Darren Dale wrote: > def myfunction(filename): > execfile(filename) > print testvar > > What am I doing wrong? I'm not familiar enough with execfile or the interactive interpreter to know what you are doing wrong, but something like: def myfunction(filename): ns=dict() execfi

function namespaces

2005-03-08 Thread Darren Dale
Hi, I have a variable saved in a file like this #contents of myfile.py: testvar = [1,2,3,4] and I am trying to write a function that does something like this: def myfunction(filename): execfile(filename) print testvar The problem I am running into is that the global name testva