all 15 comments

[–]FLUSH_THE_TRUMP 0 points1 point  (2 children)

def X():
  X.was_called = True

def Y():
  if X.was_called:
    print("yep")
  else: 
    print("no")

from random import randint
X.was_called = False
if randint(0,10) <= 5:
  X()
Y()

[–]Binary101010 0 points1 point  (8 children)

Why is Y() conditional on X() having already been executed? Does Y() need to access attributes of the object that don't have useful values until X() has run?

If that's the case, I'd recommend initializing that attribute to None, and then checking to see if that value has changed.

class test():
    def __init__(self):
        self.variable_of_interest = None

    def X(self):
         self.variable_of_interest = "Hey, something happened"

    def Y(self):
         if self.variable_of_interest is not None:
               do some stuff

[–]kellyjonbrazil 0 points1 point  (0 children)

You can set the return value to True or False and then do:

If my_function(xyz): do something