I am developing a class. The class-level data it will need is going to be relatively complex. To save typing and minimize mistakes, I would like to define a good bit of this data through functions. Also, I would like to make this data available to the user even if they aren't ready to instantiate the class. So, I wonder, is there a way to get these functions to run automatically as soon as the class is defined? As an example, I want something like
import numpy as np
def class foo:
# this should run before instantiation
def define_bar:
bar = np.range(100)
# this should also run before init
def define_something_really complicated:
bleh = # something that is too complicated for a single line or lambda
def __init__(self):
# etc.
So then the user can do something like
>>> from foopackage import foo
>>> foo.bar
array([ 0, 1, 2, 3, 4, 5, ... #etc.
>>> foo.bleh
< whatever bleh is ... >