Is it possible to create an object where object name is specified by a string
E.g.
create_object(QtGui.QLineEdit, 'myname')
myname.setText = 'created!'
That is
create_object(QtGui.QLineEdit, 'myname')
equals to
myname = QtGui.QLineEdit(self)
You can use globals. Example:
class A:
a = 'Hello'
test = globals()['A']
print test.a #It will print 'Hello'
For more information: http://www.diveintopython.net/html_processing/locals_and_globals.html
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().