Page 1 of 1

Import custon module into script

Posted: Fri Nov 14, 2014 1:41 pm
by christian.pinto
Hi all,

I am trying to define a few custom python modules to be used in my scripts. My custom module works pretty well, except for the fact that i can not import in into a script.
My idea was to do something like:

Code: Select all

import my_module
While True:
  module_obj.func()

Bu then i get the following error: No module named 'my_module'.

While the custom module works if i do: my_module.module_obj.func().

To create the custom module I took the pyb module as a reference.

Is there something specific to do to allow the module to be imported into a script??


Thanks in advance,

Christian

Re: Import custon module into script

Posted: Fri Nov 14, 2014 10:20 pm
by dhylands
If you just do:

Code: Select all

import my_module
then you'll need to prefix everything from my_module (so my_module.module_obj)

However, if you do:

Code: Select all

from my_module import module_obj
then you can use module_obj without a prefix.

This is the same between python and micropython.