Code: Select all
MicroPython v1.11-697-g7b18c0b93-dirty on 2020-02-28; A9/A9G module with RDA8955
Type "help()" for more information.
>>> import sys
...
import name 'sys' level=0
__import__:
'sys'
None
None
None
0
Module already loaded
...
Code: Select all
MicroPython v1.11-697-g7b18c0b93-dirty on 2020-02-28; A9/A9G module with RDA8955
Type "help()" for more information.
>>> import sys
...
import name 'sys' level=0
__import__:
'sys'
None
None
None
0
Module already loaded
...
This is definitely true of `sys`, but not `uos`, `umachine`, etc and many other built-in modules.
Code: Select all
$ cat /tmp/os.py
print('import os.py')
def fake_os():
print('hi')
$ pyboard --device /dev/ttyUSB0 -f cp /tmp/os.py :
cp /tmp/os.py :os.py
$ miniterm /dev/ttyUSB0 115200
--- Miniterm on /dev/ttyUSB0 115200,8,N,1 ---
--- Quit: Ctrl+] | Menu: Ctrl+T | Help: Ctrl+T followed by Ctrl+H ---
>>>
MPY: soft reboot
MicroPython v1.12-210-g1993c8cf9 on 2020-03-02; TinyPICO with ESP32-PICO-D4
Type "help()" for more information.
>>>
>>> import os
import os.py
>>> os.fake_os()
hi
>>> import uos
>>> uos.uname()
(sysname='esp32', nodename='esp32', release='1.12.0', version='v1.12-210-g1993c8cf9 on 2020-03-02', machine='TinyPICO with ESP32-PICO-D4')
>>> os.fake_os()
hi
>>>
This feature is called "weak links" -- the idea is that "os" is a weak link to "uos". (The name comes from "weak symbol" in a linker).
Hopefully the above explains everything you need...