How to get extern data for my system exception subroutine?

I am still not able to get a extern class set for my special system exception subroutine. See my example:

File ‘’ contains
#-------------------------------- Import modules -------------------------------
import importlib
import os
import sys
#-------------------------------- Initialize data ------------------------------
msg = ‘’
syspth = ‘bsx’
#*------------------------------- Once-only processing -------------------------
#------------------------------ Import function ‘webbs1’ ---------------------
flifnc = syspth + ‘/pgm/’
if not os.path.isfile(flifnc):
msg = ‘Missing function file ‘’ + flifnc + ‘’’
z = importlib.import_module(flifnc[0:-3].replace(’/’, ‘.’))
#------------------------------ Call function ‘webbs1’ -----------------------
msg, glb = z.webbs1(syspth)
print('Log information from -web-: ’ + glb.flplog)
#-------------------------------- Print message --------------------------------
if msg != ‘’:

File ‘’ contains
#=== File ‘’ =========== Process web base system (part 1/2) ===========
def webbs1(syspth):
#------------------------------ Import modules -------------------------------
import importlib
import os
import sys
import time
#------------------------------ Initialize data ------------------------------
glb = False
msg = ‘’
#------------------------------ Once-only processing -------------------------
swtrun = True
#---------------------------- Import web global data -----------------------
flicls = ‘bsx/pgm/cls/’
if not os.path.isfile(flicls):
msg = ‘Missing web global data class file ‘’ + flicls + ‘’’
z = importlib.import_module(flicls[0:-3].replace(’/’, ‘.’))
glb = z.WebGlb()
glb.syspth = syspth
#---------------------------- Initialize log data --------------------------
flilog = glb.syspth + glb._FLILOG
indwrk = flilog.rfind(’/’)
if not os.path.exists(flilog[:indwrk]):
if not os.path.isfile(flilog):
open(flilog, ‘w’, encoding=‘utf-8’).close()
glb.flolog = open(flilog, ‘a’, encoding=‘utf-8’)
glb.flplog = flilog
#---------------------------- Initialize system exception handler ----------
sys.excepthook = sysexc
xxx = xxx # WRONG statement going to function ‘sysexc’
msg = ‘Successfully executed!’
swtrun = False
return (msg, glb)

def sysexc( # System exception subroutine ------------------
exctpx, # …
excmsg, # …
trb # …
#------------------------------ Import modules -------------------------------
import traceback
#------------------------------ Create log message ---------------------------
print(‘Starting exception routine …’)
for pstwrk in range(len(traceback.format_tb(trb))-1 , -1, -1):
print(traceback.format_tb(trb)[pstwrk].replace(’\n ‘, ‘:’)[1:])
print(‘Log information from -web-: … HOW to get data from global data?’)

File '’
# File ‘’ ============== Web global data ==============================
class WebGlb:
def init(self):
#---------------------------- Initialize file names-------------------------
self._FLILOG = ‘/log/log.txt’
self._FLIFNC = ‘/pyx/.py’
self._FLIPKL = '/txt/
self._FLISBR = ‘/pyx/sbr/***.py’
#---------------------------- Initialize attributes ------------------------
self.flolog = False # Web log file object
self.flplog = False # Web log file path
self.glb = False # Web global data object
# (needed for function sysexc)
self.tblsbr = { # Table of subroutines
‘websbrlog’ : ‘’,
‘websbrtxt’ : ‘’

I am very much looking forward to your satisfactory solution!

Your question is not very clear. First, format your code as described in the about post. That makes it formatted so it will be much clearer.

I created a small example, a file called in the current working directory that contains:

    class UnexpectedText():
        quote = "Nobody expects the Spanish inquisition"

    unexpected_instance = UnexpectedText()

First we get the instance from importables:

>>> from importables import unexpected_instance
>>> print(unexpected_instance.quote)
Nobody expects the Spanish inquisition

We can also get the whole namespace as names, you know the syntax:

>>> import importables
>>> print(importables.unexpected_instance.quote)
Nobody expects the Spanish inquisition

How does this not answer your question?

Now I ask you how your function ‘UnexpectedText’ can get the required external variable like ‘glb’. In my program it contains the web global data. Namely, I want to get the web log global object in such a way that I can write the log information to that log file. Hope it’s clear enough for you.

Don’t turn my example upside down! My UnexpectedText plays the role of your WebGlb. Let me rephrase my question, maybe that will make it clearer: What is so special about the WebGlb module that you think you cannot import it? If you can import it, you can instantiate the WebGlb class and use the object so created to fill your log.

Some remarks:

  1. Why do you put all the items in the class WebGlb? They will not change and are in no way related to each other. Fields at the module level will suffice.
  2. Global data is evil. Why do you not keep the items with the classes they belong to? E.g. the logging directory with the code producing logs?
  3. Related: The standard library has a logging module which contains a lot of goodies for logging. Use that and do not reinvent the wheel.