w+ : Opens a file for both writing and reading. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing.Code: Select all
with open('log.tx', 'w+') as f: v = int(f.read()) v = v+1 f.write(str(v))
File mode 'w+'
File mode 'w+'
Does MicroPython support the 'w+' file mode?
Re: File mode 'w+'
Code: Select all
MicroPython v1.9.2-144-g98dd126 on 2017-10-05; ESP module with ESP8266
Type "help()" for more information.
>>> with open('test.txt', 'w+') as f:
... f.write('hello, world')
...
...
...
12
>>> import uos
>>> uos.listdir("/")
['boot.py', 'webrepl_cfg.py', 'max7219.py', 'lanmon.py', 'test.txt']
Code: Select all
benalb@t410 ~/tmp/micropython
ampy -p /dev/ttyUSB0 get test.txt
hello, world