python - Converting Variables In List to Local Variables -
is there way convert variables in list local variables in python?
more specifically, i've been doing
x = imp.load_source("test","./test") but don't want have x.var1
i want able var1 reference each imported element.
is possible?
i'm not sure understand question, , i'm not sure you're trying idea (think of zen of python: "namespaces 1 honking great idea--let's more of those!"). trying load files of python source code , have access local variables?
again, going reiterate warning these bad ideas.
a. why using imp module? import module normal. take of it's local scope , import local scope:
from test import * this classic example of bad python. don't it. every python programmer tell never use _ import *. accomplish you're trying do, you'll override local variables or built-ins , cause obscure bugs.
b. use execfile. takes source of file , executes in local scope. so:
execfile('./test', globals(), locals()) this has same warnings last one: might override local variables (including built-ins) , cause obscure bugs.
Comments
Post a Comment