Python Forum
Use builtins variable for single entry point. Good Idea or not?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Use builtins variable for single entry point. Good Idea or not?
#1
Question 
Hello!

There is a QT project. It includes several services and all sorts of constants, flags and states that are used throughout the project.
For global access to a single entry point to all properties, I did this:
import sys
import builtins
import asyncio
from asyncqt import QEventLoop
from PySide2 import QtWidgets

import core
import logger
    
    
def main():
    logger.info('<Your app is running PID:{}>'.format(
        QtWidgets.QApplication.applicationPid()))
        
    qApp = QtWidgets.QApplication(sys.argv)
    loop = QEventLoop(qApp)
    asyncio.set_event_loop(loop)
        
    try:
        builtins.Core = core.Core(qApp)
        loop.create_task(Core.Run())
    
    except Exception as e:
        logger.critical("ERROR [INIT]: {}".format(e))
        sys.exit()

    try:
        loop.run_forever()
    except Exception as e:
        logger.exception(e)

    loop.close()
Now I have access to all the necessary components from anywhere in the project through the Core variable.

Please provide strong reasons why this is a bad idea.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020