Cross class variable only initialized once
Question: I'm having some troubles with the scope in Python. I initialize a variable
(`basePrice`) in a class (`STATIC`). The value is static and the
initialization takes some work, so I only want to do it once. Another class
`Item`, is a class that is created a lot. An `Item` object needs to calculate
its variable `price` by using `basePrice`. How can I initialize `basePrice`
only once and use it in an `Item` object?

    
    
    class STATIC:
        basePrice = 0
        def __init__(self):
            self.basePrice = self.difficultCalculation()
        def getBasePrice()
            return self.basePrice
    
    
    import STATIC
    class Item:
        price = 0
        def __init__(self,price_):
            self.price = price_ - STATIC.getBasePrice()
    


Answer: It might be better to write a module. For example, create the file `STATIC.py`
as shown below.

    
    
    basePrice = difficultCalculation()
    
    def difficultCalculation():
        # details of implementation
    
    # you can add other methods and classes and variables
    

Then, in your file containing `Item`, you can do:

    
    
    from STATIC import basePrice
    

This will allow all access to `basePrice` from anywhere within that file.

