What purpose does the sys module have in use with PyQt After all, in fact, it can work without it.

Example of use with sys

 import sys from PyQt5.QtWidgets import * class Ex(QWidget): def __init__(self): super().__init__() self.setWindowTitle('Тест') self.resize(400, 400) if __name__ == '__main__': app = QApplication(sys.argv) main = Ex() main.show() sys.exit(app.exec_()) 

Example using without sys :

 from PyQt5.QtWidgets import * class Ex(QWidget): def __init__(self): super().__init__() self.setWindowTitle('Тест') self.resize(400, 400) if __name__ == '__main__': app = QApplication([]) main = Ex() main.show() app.exec() 

What is the point of using this module?

    1 answer 1

    This is only necessary so that the script can return the return code to the calling process.

    • And how best to use without sys or just is not entirely clear, and how to understand the return code to the calling process - Twiss
    • Each program starts something - another program or shell of the operating system. Upon completion, the program must return a number to the calling process indicating the status of the program’s completion . For example, 0 may indicate successful completion of a program, and other numbers an error code. Therefore, it is more appropriate to use sys.exit(app.exec_()) . - Sergey Gornostaev