python - Initialize variable if class method is run -


i have class, like

class d:     def __init__(self):         """some variables"""     def foo(self):         """generates lots of data""" 

i able store of data foo creates within instance of class foo being called from. creating new initialization variable, once method called. if user never calls foo, no need have generated data begin with.

thanks!

how make flag if data generated?

class d:     def __init__(self):         self.already_generated = false         """some variables"""     def foo(self):         """generates lots of data"""         if not already_generated:             self.generate()...             already_generated = true      def generate(self,...): 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -