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
Post a Comment