I have some strings of variables names, that must initially be strings (due to file IO).
The variables these correspond to are variable names of PyQt4 widgets, embed in two classes.
I need these strings able to be converted to the actual variable names to use them in functions.
(Kind of like how you ‘int’ a string of a number)
Here’s the code (Showing the Class Madness)
FIRST FILE
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
self.VariableName = QWidget(whatever)
SECOND FILE
from FIRST_FILE import Ui_MainWindow
class Start(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
def ResetDropBoxes(self):
X = "VariableName"
self.ui.X.Function()
Some might recognise this as the format of python code generated by Pyuic4 (Qt Designer)
The last two lines of the Second File are the trouble.
I get the error message “Ui_MainWindow() has no attribute ‘X'”.
I had no idea where to go with this, except an attempt with ‘eval’.
I tried things such as…
X = self.ui.eval("VariableName")
This prompted errors “Ui_MainWindow() has no attribute ‘eval’
X = eval("VariableName")
“VariableName is not defined”
X = "VariableName"
eval(self.ui.X.Function())
“Ui_MainWindow() has no attribute ‘X'”
I could use any and all help for this matter!
I feel that eval gets me a step closer, but using these nested classes inhibits it!
HALP’?!
DETAILS:
– Python 2.7.1
– Windows 7 (32 bit)
– IDLE 1.8
– PyQt4
– Qt Designer
Try
See here for more info on
getattr.