'Proper import of modules in Colab
i have a question regarding the proper way to import modules in colab. I used the folder structure from "6.4.Packages" in https://docs.python.org/3/tutorial/modules.html:
sounds/
__init__.py
effects/
__init__.py
echo.py
def echo_func(arg):
return something
surround.py
def surround_func(arg):
return somehing
The files are located in path/to/sounds on my google.drive account, and i'm mounting my drive via:
from google.colab import drive
drive.mount(mount_path)
import sys
sys.path.insert(0, path/to/sounds)
The problem that i have now is, that i want to import the modules in this way
import sounds.effects as se
echo_func = se.echo.echo_func(arg)
---------
AttributeError: module 'sounds.effects' has no attribute 'echo'
---------
A workaround at the moment is:
import sounds.effects.echo
import sounds.effects as se
echo_func = se.echo.echo_func(arg)
So if i import sounds.effects.echo first, i can import sounds.effects and the module echo in se.echo is found. The same goes for surrounds:
import sounds.effects.surround
import sounds.effects as se
surround_func = se.surround.surround_func(arg)
Is there a way, that this double-import-workaround is not needed? I haven't found any working solution for this problem yet,
thanks in advance
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
