having multiples clasess in a module in a package in Python?
Question: I'm having trouble understanding packages in Python. In particular, is it
possible to have multiple classes in a module in a package in Python. For
example:

    
    
    Kitchen/            Top-level package
        __init__.py     Initialize the package kitchen
        Fridge.py       module Fridge.py
            Food        This is a class in module Fridge
            Temperature This is another class in module Fridge
        Recipe.py
            BeefStake   This is a class in module Recipe.py
    

In the `__init__.py`, the code will be:

    
    
    from Fridge import Food, Temperature
    from Recipe import BeefStake
    __all__ = ['Fridge', 'Recipe']
    

Then I would create an instance of the Temperature class by

    
    
    from Kitchen import *
    f = Food()
    T = Temperature()
    

I tried this, and only making `f = Food()` works. The other one showed up an
error, something like `NameError: name 'Temperature' is not defined`

If anyone knows if it is possible to have 2 classes like this in a module in a
package in Python. If so, what could be the problem in this approach?


Answer: The code you showed us won't work for _either_ `Food` or `Temperature`. You
explicitly put this in `Kitchen`:

    
    
    __all__ = ['Fridge', 'Recipe']
    

This means that, even though you've imported `Food` and `Temperature` into
`Kitchen`, you don't re-export them. So, `f = Food()` will raise a
`NameError`.

If you change this to, say:

    
    
    __all__ = ['Food', 'Temperature']
    

Now everything works fine.

My guess is that in your real code, you made one of two mistakes:

  * Forgot to include `Temperature` in `__all__`, just as you did with both `Food` and `Temperature` here, or
  * Had a typo somewhere, e.g., `t = temperature()` with a lowercase `t`.

Normally I'd suspect that the first is more likely… but given that you're
inconsistent with capitalization, and misspelled `BeefSteak`, I'd check the
second here.

