python - Should I use `app.exec()` or `app.exec_()` in my PyQt application? -
i use python 3 , pyqt5. here's test pyqt5 program, focus on last 2 lines:
from pyqt5.qtcore import * pyqt5.qtwidgets import * import sys class window(qwidget): def __init__(self,parent=none): super().__init__(parent) self.setwindowtitle('test') self.resize(250,200) app=qapplication(sys.argv) w=window() w.show() sys.exit(app.exec()) #sys.exit(app.exec_())
i know exec
language keyword in python. code on official pyqt5 documentation (specifically object destruction on exit part). see example shows use of app.exec()
confuses me.
when tested on machine. found there no visible difference end. both , without _
produces same output in no time difference.
my question is:
- is there wrong going when use
app.exec()
? clashing python's internalexec
? suspect because bothexec
's executing something. - if not, can use both interchangeably?
that's because until python 3, exec
was reserved keyword, pyqt devs added underscore it. python 3 onwards, exec
no longer reserved keyword (because builtin function; same situation print
), made sense in pyqt5 provide version without underscore consistent c++ docs, keep version underscore backwards compatibility. pyqt5 python 3, 2 exec
functions same. older pyqt, exec_()
available.
Comments
Post a Comment