registering submodules of submodules with namespaces/import structure #15750
NiHoffmann
started this conversation in
General
Replies: 1 comment
-
Additional Information, i'm Building my Micropython as an Embed Port for a different Project. Not for a microcontroller specific. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello im building a micropython port at the moment,
Im having trouble registering submodules
i want to be able to have a module structure
example_package.foo.bar
and be able to callfrom example_package.foo import bar
when using the example for subpackages(provided by micropython) this does not work, the module can be accesses via:
from example_package import foo
foo.bar
this is not satisfactory for my usecase.
i have also tried what is done in the pybricks project they just use
pybricks.<module>
as name space and register it with the help of a module nameexample_package_dot_foo
mapped toexample_package.foo
this will result is pybricks or in my case example_package not to be an actual module, so
import example_package
would not be viablelastly i tried to combine both approaches and register a top module example_package this will get the foo module passed in its dictionary the foo module does the same with the bar. Now i also register the foo module as
example_package_dot_foo(with qstring example_package.foo)
this some what works i can now use:
import example_package
from example_package import foo
from example_package.foo import bar
but it has one problem when i run
import example_package.foo
i will not import the module foo as suchbut instead i will import the module foo under the name example_package , so then i use
import example_package.foo
print(example_package)
i will get the information that i printed the foo module while
print(foo)
will just throw an errorDoes Micropython only allow Importing modules "one layer deep" ? (this is what it looks like to me right now)
<- this is the most important question for me right now
Did i do something wrong maybe ? (my last approach is probably not how micropython is intended to be used)
Is this even possible without modifying Micropython ?
Lastly am i just missing something big with how modules can be registered and organized ?
Thanks for any help with this.
Beta Was this translation helpful? Give feedback.
All reactions