How to obtain a list of importable modules?

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
pagano.paganino
Posts: 56
Joined: Fri Sep 11, 2015 10:47 pm
Location: Italy

Re: How to obtain a list of importable modules?

Post by pagano.paganino » Thu Nov 09, 2017 2:56 pm

Hi Lisa,
i haven't esp32, on pyboard a trick can be:

Code: Select all

import io
import os

class DUP(object):

    def __init__(self, s):
        self.s = s

    def write(self, data):
        self.s += data
        return len(data)

    def readinto(self, data):
        return 0

s = bytearray()
os.dupterm(DUP(s))
help('modules')
os.dupterm(None)
into 's' you can see the output from help('modules')

LisaM
Posts: 6
Joined: Tue Nov 07, 2017 6:11 pm

Re: How to obtain a list of importable modules?

Post by LisaM » Thu Nov 09, 2017 3:10 pm

AttributeError: 'module' object has no attribute 'dupterm'

:(

User avatar
pythoncoder
Posts: 2031
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: How to obtain a list of importable modules?

Post by pythoncoder » Thu Nov 09, 2017 6:17 pm

@pagano.paganino Ingenious!
@LisaM I think dupterm is yet to be implemented on ESP32.
Peter Hinch

LisaM
Posts: 6
Joined: Tue Nov 07, 2017 6:11 pm

Re: How to obtain a list of importable modules?

Post by LisaM » Fri Nov 10, 2017 12:29 am

Running on pyboard:

File "test.py", line 17, in <module>
ValueError: need a UART object

test.py:

Code: Select all

import io
import os

class DUP(object):

    def __init__(self, s):
        self.s = s

    def write(self, data):
        self.s += data
        return len(data)

    def readinto(self, data):
        return 0

s = bytearray()
os.dupterm(DUP(s))
help('modules')
os.dupterm(None)
print(s)
Line 17: os.dupterm(DUP(s))

So... not working on pyboard either...

User avatar
Roberthh
Posts: 778
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: How to obtain a list of importable modules?

Post by Roberthh » Fri Nov 10, 2017 6:34 am

You might need to update. It works on my PyBoard:
(sysname='pyboard', nodename='pyboard', release='1.9.3', version='v1.9.3-11-gb9580b8-dirty on 2017-11-07', machine='PYBv1.1 with STM32F405RG')

LisaM
Posts: 6
Joined: Tue Nov 07, 2017 6:11 pm

Re: How to obtain a list of importable modules?

Post by LisaM » Fri Nov 10, 2017 11:02 am

MicroPython v1.9.2-173-g829c329-dirty on 2017-10-20; PYBv1.0 with STM32F405RG
Hmmm, little bit difference. I was going to update anyway, due to #3379. I'll test it after the update.

It also need to work on all of my testbeds, being : Orange PI Zero, ESP32, NodeMCU, Pyboard.
For now i solved it by using the __init__.py file (in the plugins dir) to write down which plugins are available in the (frozen!) plugins dir.

Thx!

Edit: Tested with new release and there it works!

Post Reply