2023-05-11 05:28:35 +01:00
|
|
|
f = open("data/file1", "rb")
|
2014-11-16 22:16:14 +00:00
|
|
|
print(f.seek(6))
|
|
|
|
print(f.read(5))
|
2015-08-05 00:45:30 +01:00
|
|
|
print(f.tell())
|
2014-11-16 22:16:14 +00:00
|
|
|
|
|
|
|
print(f.seek(0, 1))
|
|
|
|
print(f.read(4))
|
2015-08-05 00:45:30 +01:00
|
|
|
print(f.tell())
|
2014-11-16 22:16:14 +00:00
|
|
|
|
|
|
|
print(f.seek(-6, 2))
|
|
|
|
print(f.read(20))
|
2015-08-05 00:45:30 +01:00
|
|
|
print(f.tell())
|
2014-11-16 22:16:14 +00:00
|
|
|
|
|
|
|
print(f.seek(0, 0))
|
|
|
|
print(f.read(5))
|
2015-08-05 00:45:30 +01:00
|
|
|
print(f.tell())
|
2014-11-16 23:56:37 +00:00
|
|
|
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
# test text mode
|
2023-05-11 05:28:35 +01:00
|
|
|
f = open("data/file1", "rt")
|
2014-11-16 23:56:37 +00:00
|
|
|
print(f.seek(6))
|
|
|
|
print(f.read(5))
|
2015-08-05 00:45:30 +01:00
|
|
|
print(f.tell())
|
2014-11-16 23:56:37 +00:00
|
|
|
f.close()
|
2015-12-23 22:37:02 +00:00
|
|
|
|
|
|
|
# seek closed file
|
2023-05-11 05:28:35 +01:00
|
|
|
f = open("data/file1", "r")
|
2015-12-23 22:37:02 +00:00
|
|
|
f.close()
|
|
|
|
try:
|
|
|
|
f.seek(1)
|
|
|
|
except (OSError, ValueError):
|
|
|
|
# CPy raises ValueError, uPy raises OSError
|
|
|
|
print("OSError or ValueError")
|