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

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

$
0
0
@hippy Yes you are correct but

I was talking about one argument!

On micropython.
On one argument print the full first argument information
On two arguments the second argument is the length.
On three arguments the second is the start index and the third is the length. P.S. start index is 0.

The second and third argument are integer this is why it complains about "unable to convert to int")

Code:

testfile = "a.dat"test1_string="0123456789"try:    with open(testfile, 'a') as file:            # write 3 bytes from the string            file.write("write(string)\n")            file.write(test1_string)            file.write("\nwrite(string,3)\n")            file.write(test1_string,3)            file.write("\nwrite(string,3,4)\n")            file.write(test1_string,3,4)            print("*** Sucessful written***\n\n")except Exception as e:        print(e)               print(open(testfile).read())
and the result

Code:

>> %Run -c $EDITOR_CONTENT*** Sucessful written***write(string)0123456789write(string,3)012write(string,3,4)3456>>> 

Statistics: Posted by danjperron — Tue Apr 01, 2025 4:16 pm



Viewing all articles
Browse latest Browse all 8013

Trending Articles