issue with "from example_dir import *"

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
walecka
Posts: 17
Joined: Wed Apr 08, 2020 9:50 pm

issue with "from example_dir import *"

Post by walecka » Mon Apr 27, 2020 9:35 pm

i have loaded a directory with library module files onto my device using the ./pyboard tool such that the directory tree on my device looks like this

Code: Select all

/flash
       'boot.py'
       'main.py'
       /example_dir
              'mod1.py'
              'mod2.py'
              '__init__.py'
__init__.py contains only the following line of code:
__all__ = ["mod1", "mod2"]

when i try to call
from example_dir import *

from the REPL, i get no error messages, but nothing seems to happen. I cannot call mod1.somefunction(). When I do, I get the following error

Code: Select all

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'mod1' isn't defined
Is this known behavior? I am not an expert, but from I have read I believe that calling
from example_dir import *
should import both mod1 and mod2 and allow me to use their functions
Last edited by jimmo on Tue Apr 28, 2020 3:14 am, edited 1 time in total.
Reason: Add [code] formatting

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: issue with "from example_dir import *"

Post by jimmo » Tue Apr 28, 2020 3:46 am

Unfortunately __all__ is currently unsupported in MicroPython. I have added a test case for this so it automatically gets added to the docs at http://docs.micropython.org/en/latest/g ... tml#import

https://github.com/micropython/micropython/pull/5979

The workaround is to write:

Code: Select all

from . import mod1, mod2
instead

Post Reply