importing user defined modules...

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
domgiles
Posts: 10
Joined: Fri Aug 08, 2014 2:54 pm

importing user defined modules...

Post by domgiles » Fri Sep 12, 2014 11:59 am

I feel a complete idiot for not being able to figure out how to do this...

I just want to be able to create a module and import it. So if I had something like

Code: Select all

class Welcomer:

    def __init__(self):
        '''
        Constructor
        '''
        
    def sayHello(self, name):
        return 'Hello ' + name
I'm working under possibly the naive impression that all I would need to do is to save it in the / directory of the folder and then simply import it but what ever I try I get

Code: Select all

ImportError: No module named 'Welcomer'
I've checked sys and it seems to indicate that micro python should pick it up from either the root or /lib

Code: Select all

>>> sys.path      
['0:/', '0:/lib']
>>>
Can someone put me out of my misery and explain what I'm doing wrong.

fma
Posts: 164
Joined: Wed Jan 01, 2014 5:38 pm
Location: France

Re: importing user defined modules...

Post by fma » Fri Sep 12, 2014 12:04 pm

Is your code on the sd card? You need to add '1:/' path in your sys.path...
Frédéric

domgiles
Posts: 10
Joined: Fri Aug 08, 2014 2:54 pm

Re: importing user defined modules...

Post by domgiles » Fri Sep 12, 2014 12:57 pm

Ohhhhh... I'll give that ago. Thanks.

Not sure how I missed this

http://wiki.micropython.org/Importing-Modules

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: importing user defined modules...

Post by dhylands » Fri Sep 12, 2014 2:16 pm

fma wrote:Is your code on the sd card? You need to add '1:/' path in your sys.path...
Or '/sd' if you're using new firmware.

Post Reply