Page 1 of 1

__import__ not working

Posted: Thu May 13, 2021 9:14 am
by Lebowski
Hi,
im using MicroPython v1.14-457-g3bf6c7f12

I've a module foo.bar.foobar

When running

Code: Select all

import foo.bar.foobar
everything is fine, i can use the module.
When running (for some reason i've to do it this way)

Code: Select all

__import__("foo.bar.foobar")
the module i not import. Ther is nor rrrormessage while running this command. But i get an
AameError: name 'foo' isn't defined
Any ideas?

Thank you

Re: __import__ not working

Posted: Thu May 13, 2021 1:32 pm
by stijn
Cannot reproduce this. Can you add more information: directory structure, value of sys.path, which port you are using?

Re: __import__ not working

Posted: Thu May 13, 2021 3:37 pm
by Lebowski
Hi,

i think i got it: __import__("foo.bar.foobar") returns a modules object.

Code: Select all

m=__import__("foo.bar.foobar")
To create an object from foo.bar.foobar.Foo you have to use

Code: Select all

f=m.Foo()