Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 8051

General • Re: "Can't convert str to int' error writing to SD card

$
0
0
The problem was spotted by horuable right away.
I guess the problem is with this line:
Code: Select all

file.write(test1_string,' ')

Code:

testfile = "a.dat"test1_string="0123456789"try:        with open(testfile, 'a') as file:        # write string + new line        r = file.write(test1_string+'\n')        print("bytes written", r)except Exception as e:        print(e)   print("\n--- Read file ---",testfile,"\n")print(open(testfile).read())
and the result after two runs

Code:

>>> %Run -c $EDITOR_CONTENTbytes written 11--- Read file --- a.dat 01234567890123456789>>> 
The python and micropython file.write is the same. https://www.w3schools.com/python/ref_file_write.asp

Statistics: Posted by danjperron — Tue Apr 01, 2025 2:43 pm



Viewing all articles
Browse latest Browse all 8051

Trending Articles