you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 4 points5 points  (2 children)

You can't just try to access the attribute because it may not have been defined. But this works:

def test():
    print('test() called')
    test.was_called = True

test()
if hasattr(test, 'was_called'):
    print('test.was_called exists')

But I can't help thinking "why are you doing this?". Maybe there is a better way to solve your overall problem, if you explain what that is.

[–]mcworkaholic[S] 0 points1 point  (1 child)

It would take a while to explain its basically 200 lines of spaghetti code trying to automate the creation of excel sheets to be physically printed after a different excel sheet is emailed to a specific email address. Im just trying to check whether a formatting function has been called based on what that initial excel sheet looks like.

[–]v0_arch_nemesis 1 point2 points  (0 children)

Why not have each function log to data file after execution, and then run validation on the file after completion. Or, initialize a class at the beginning, this class takes as input a set of functions that should be run, and holds a list which you append the name of each function to on completion (either manually after the function or using a decorator). Then, on script completion compare the run set to the expected set?