2014-10-18 19:44:07 +00:00
|
|
|
b = bytearray(30)
|
2023-05-11 04:28:35 +00:00
|
|
|
f = open("data/file1", "rb")
|
2014-10-18 19:44:07 +00:00
|
|
|
print(f.readinto(b))
|
|
|
|
print(b)
|
2023-05-11 04:28:35 +00:00
|
|
|
f = open("data/file2", "rb")
|
2014-10-18 19:44:07 +00:00
|
|
|
print(f.readinto(b))
|
|
|
|
print(b)
|
2015-12-23 22:37:02 +00:00
|
|
|
|
|
|
|
# readinto() on writable file
|
2023-05-11 04:28:35 +00:00
|
|
|
f = open("data/file1", "ab")
|
2015-12-23 22:37:02 +00:00
|
|
|
try:
|
|
|
|
f.readinto(bytearray(4))
|
|
|
|
except OSError:
|
2020-03-23 02:26:08 +00:00
|
|
|
print("OSError")
|