In addition to what horuable stated: looks as if the second parameter in write() is the number of bytes written from the buffer.
Code:
testfile = "a.dat"test1_string="0123456789"try: with open(testfile, 'w') as file: # write 3 bytes from the string r = file.write(test1_string, 3) print("bytes written", r) # newline file.write("\n") # write complete string r = file.write(test1_string) print("bytes written", r) except Exception as e: print(e) # verify content of filetry: with open(testfile, 'r') as file: r = file.read() print("file read", r)except Exception as e: print(e)print("complete")Statistics: Posted by ghp — Tue Apr 01, 2025 1:44 pm