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,
> 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
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
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
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
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