I created /flash/make_x.py:
Code: Select all
def incr():
try:
with open('/flash/x.py', 'r') as f:
lines = f.readlines()
fields = lines[0].split()
old_x = int(fields[2])
new_x = old_x + 1
except OSError:
new_x = 0
with open('/flash/x.py', 'w') as f:
print('Updating x to {}'.format(new_x))
f.write('value = {}\n'.format(new_x))
f.write("print('value = {}'.format(value))\n")
Code: Select all
def reload(mod):
import sys
mod_name = mod.__name__
del sys.modules[mod_name]
return __import__(mod_name)
Code: Select all
MicroPython v1.5.1-117-g57dcfa3-dirty on 2015-12-13; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> import make_x
>>> make_x.incr()
Updating x to 0
>>> import x
value = 0
>>> x.value
0
>>> make_x.incr()
Updating x to 1
>>> x = reload(x)
value = 1
>>> x.value
1
>>> make_x.incr()
Updating x to 2
>>> x.value
1
>>> x = reload(x)
value = 2
>>> x.value
2
>>>