FileIO: Difference between revisions
Jump to navigation
Jump to search
Line 16: | Line 16: | ||
print(str(i) + "; " + str(random_integer)) | print(str(i) + "; " + str(random_integer)) | ||
file.close() | file.close() | ||
<syntaxhighlight | </syntaxhighlight> |
Revision as of 19:45, 1 June 2024
Description
Write and read files using MircoPython.
Write to File
# write 100 random values to a file
import random
import os
file = open('datafile01.txt', 'a')
for i in range(100):
random_integer = random.randint(1, 1000)
file.write(str(i) + "; " + str(random_integer) + "\n")
print(str(i) + "; " + str(random_integer))
file.close()