I have some python module, that I import as:
from mygraph.draw import pixel
The file structure looks like that:
mygraph/
__init__.py
draw.py
and draw.py
contains def pixel()
Now, I want to add another function, line()
, and I want to import it as
from mygraph.draw import line
I can simply add line
to draw.py
. But, I would like to have line()
in a separate file line.py
and not mess with draw.py. But, if I place it in a separate file, it will be imported as
from mygraph.line import line
and that is not what I want...
Is it possible to "alias" somehow the line.py
so it is visible in draw
module, but is in separete file? I thought about adding a dummy function in draw
def line():
return real_line.line()
but in this case I won't have a "docstring" from the original line
, and I will loose some performance on calling the real line function.
Try this in your draw.py
module:
from line import line
and you should be able to invoke it as mygraph.draw.line
, and import it the way you wanted.
I do this a lot in my __init__.py
files: expose the primary API this way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With