Why does the example below only work when creating a useless variable _ ?
The variable _ is assigned and never used. I would suggest that a good compiler would optimize and not even create it, but that really matters.
If I remove _ = and leave only Test() , then a window is created, but it instantly flickers and disappears, and python is eternally maintained.
Here is the code:
import sys from PyQt4 import QtGui class Test(QtGui.QWidget): def __init__(self): super().__init__() self.show() app = QtGui.QApplication(sys.argv) _ = Test() sys.exit(app.exec_())
source share