Page 2 of 3
Re: How to obtain a list of importable modules?
Posted: Thu Nov 09, 2017 2:56 pm
by pagano.paganino
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')
Re: How to obtain a list of importable modules?
Posted: Thu Nov 09, 2017 3:10 pm
by LisaM
AttributeError: 'module' object has no attribute 'dupterm'
Re: How to obtain a list of importable modules?
Posted: Thu Nov 09, 2017 6:17 pm
by pythoncoder
@pagano.paganino Ingenious!
@LisaM I think dupterm is yet to be implemented on ESP32.
Re: How to obtain a list of importable modules?
Posted: Fri Nov 10, 2017 12:29 am
by LisaM
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...
Re: How to obtain a list of importable modules?
Posted: Fri Nov 10, 2017 6:34 am
by Roberthh
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')
Re: How to obtain a list of importable modules?
Posted: Fri Nov 10, 2017 11:02 am
by LisaM
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!
Re: How to obtain a list of importable modules?
Posted: Fri Jun 15, 2018 12:29 pm
by upymar
How do I get a list of available functions of a specific module?
In another thread I read something about e.g. the ntptime module but didn't find anything in the documentation.
So where do I get the information how to use modules and their functions which are not mentioned in the documentation?
Thanks and best regards
Re: How to obtain a list of importable modules?
Posted: Sat Jun 16, 2018 6:52 am
by pythoncoder
ntptime is not included on the Pyboard by default as it has no network connection, but it can be found on the ESP8266.
provides a list of compiled-in modules. This list does not include modules you might have put in the device's filesystem.
will list its methods. Or you can look at the code in the
source tree.
Ideally all these modules would be documented but sometimes, unfortunately, you do have to track down the code and take a look.
DUP class above
Posted: Sun Jul 08, 2018 6:34 am
by pythoncoder
For anyone wanting to use the DUP class, in
this forum thread @Damien said:
There was a recent change to how this stuff works behind the scenes and you now need to derive the DUP class from io.IOBase: class DUP(io.IOBase)
Re: How to obtain a list of importable modules?
Posted: Sat Oct 20, 2018 1:02 pm
by HermannSW
pythoncoder wrote: ↑Sat Jun 16, 2018 6:52 am
provides a list of compiled-in modules. This list does not include modules you might have put in the device's filesystem.
Interesting, I compared my ESP01s
Code: Select all
MicroPython v1.9.4-272-g46091b8a on 2018-07-18; ESP module with ESP8266
and ESP32
Code: Select all
MicroPython v1.9.4-623-g34af10d2e on 2018-10-03; ESP32 module with ESP32
Micropython modules (by "$ cat | for w in `cat`; do echo $w; done | sort > esp__.txt" and copy&paste).
There are 3 modules that only exist on ESP8266, and 10 modules that only exists on ESP32:
Code: Select all
$ diff --side-by-side -W 35 esp8266.txt esp32.txt
apa102 | apa106
array array
binascii binascii
_boot _boot
btree btree
builtins builtins
> cmath
collections collections
dht dht
ds18x20 ds18x20
errno errno
esp esp
> esp32
flashbdev flashbdev
framebuf framebuf
gc gc
hashlib hashlib
> heapq
inisetup inisetup
io io
json json
lwip <
machine machine
__main__ __main__
math math
micropython micropython
neopixel neopixel
network network
ntptime ntptime
onewire onewire
_onewire _onewire
os os
port_diag <
random random
re re
select select
socket socket
ssl ssl
struct struct
sys sys
> _thread
time time
ubinascii ubinascii
ucollections ucollections
ucryptolib ucryptolib
uctypes uctypes
uerrno uerrno
uhashlib uhashlib
> uhashlib
uheapq uheapq
uio uio
ujson ujson
> umqtt/robust
> umqtt/simple
uos uos
upip upip
upip_utarfile upip_utarfile
> upysh
urandom urandom
ure ure
> urequests
uselect uselect
usocket usocket
ussl ussl
ustruct ustruct
utime utime
utimeq utimeq
uzlib uzlib
webrepl webrepl
_webrepl _webrepl
webrepl_setup webrepl_setup
websocket websocket
websocket_hel websocket_hel
zlib zlib
$
I went a step further and wanted to compare the common module features between both MicroPythons:
Code: Select all
$ comm -12 esp8266.txt esp32.txt > common.mod
$
With webrepl_client.py "-r" option and input redirect this was easy to do (I did reconnect to esp8266 Wlan after the first command was executed while connected to ESP32 Wlan):
Code: Select all
$ webrepl_client.py -p abcd -r 192.168.4.1 < <(sleep 1 && for m in `cat common.mod`; do echo -e "help(\"$m\")"; done; echo "exit") > esp32.detail
$ webrepl_client.py -p abcd -r 192.168.4.1 < <(sleep 1 && for m in `cat common.mod`; do echo -e "help(\"$m\")"; done; echo "exit") > esp8266.detail
$
First I converted to Unix format. The diffs.txt file is attached:
Code: Select all
$ dos2unix esp32.detail esp8266.detail
dos2unix: converting file esp32.detail to Unix format ...
dos2unix: converting file esp8266.detail to Unix format ...
$
$ diff --side-by-side -W 60 esp8266.detail esp32.detail > diffs.txt
There is no feature that does exist on esp8266 Micorpython only, but there are 248 in the 62 common modules that exist on esp32 only:
Code: Select all
$ diff --side-by-side esp8266.detail esp32.detail | grep " <"
$ diff --side-by-side esp8266.detail esp32.detail | grep " >" | wc --lines
248
$
But there are only 4 different features:
Code: Select all
$ grep " >" diffs.txt | sort -u
> center -- <function>
> partition -- <function>
> rpartition -- <function>
> splitlines -- <function>
$
P.S:
Ooops -- I will redo the evaluation, eg. for module utime I did
which is wrong, instead this is needed: