To create local variable, you can get the dictionary of global variables using globals()
function . Example -
gbl = globals()
gbl['myname'] = QtGui.QLineEdit
gbl['test'] = 1234
test
>> 1234
For local variables with locals()
function , which returns the dictionary of local variables (a copy of the local namespace
) , you may use this to set the variable, only if you are outside a function and directly in the script part, but setting to the dictionary provided by locals()
would not work inside a function (you will not be able to access that variable , even in that function) , when using it outisde the function it has exactly same effect as globals()
.