Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pulling python module up into package namespace

Tags:

If I have a directory structure like this:

package/
    __init__.py
    functions.py      #contains do()
    classes.py        #contains class A()

And I want to be able to call

import package as p

How do I make the contents of functions, classes, accessible as:

p.do()
p.A()

in stead of:

p.functions.do()
p.classes.A()

The subdivision in files is only there for convenience (allowing easier collaboration), but I'd prefer to have all the contents in the same namespace.


Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!