georg
georg

Reputation: 215049

Implicit import from submodules

I've got a package like this:

 foo/
    __init__.py
    bar.py
    baz.py

I'd like to have submodules' functions automatically available when I import foo. So if bar.py has def spam() somewhere, I'd like to be able to call it directly like foo.spam(). What would be the best way to achieve that?

Upvotes: 3

Views: 189

Answers (1)

Daniel Roseman
Daniel Roseman

Reputation: 600059

Inside __init__.py, do from bar import spam.

Upvotes: 4

Related Questions