Skip to content Skip to sidebar Skip to footer

Python Global Object Variable

I want to make use on an object that has been instantinated inside of a class from a standalone module. I am trying to do this by makeing the object reference global. I think I wan

Solution 1:

You must declare global variable outside from class.

## Code file something.pyimport moduleFile

adminMenu = NoneclassA():
    defcheckAdmin(self):
        global adminMenu
        adminMenu = SRMadminMenu()

then moduleFile.py,

from something import adminMenu

defmoduleFile_Admin_Menu():
    global adminMenu
    adminMenu.createSubMenu("Module Administration")

Note: If you will not change adminMenu variable, you don't have to write global adminMenu

Post a Comment for "Python Global Object Variable"