circuitpython/tests/io/file_seek.py

35 lines
560 B
Python
Raw Normal View History

2014-11-16 17:16:14 -05:00
f = open("io/data/file1", "rb")
print(f.seek(6))
print(f.read(5))
print(f.tell())
2014-11-16 17:16:14 -05:00
print(f.seek(0, 1))
print(f.read(4))
print(f.tell())
2014-11-16 17:16:14 -05:00
print(f.seek(-6, 2))
print(f.read(20))
print(f.tell())
2014-11-16 17:16:14 -05:00
print(f.seek(0, 0))
print(f.read(5))
print(f.tell())
f.close()
# test text mode
f = open("io/data/file1", "rt")
print(f.seek(6))
print(f.read(5))
print(f.tell())
f.close()
2015-12-23 17:37:02 -05:00
# seek closed file
2021-03-15 09:57:36 -04:00
f = open("io/data/file1", "r")
2015-12-23 17:37:02 -05:00
f.close()
try:
f.seek(1)
except (OSError, ValueError):
# CPy raises ValueError, uPy raises OSError
2021-03-15 09:57:36 -04:00
print("OSError or ValueError")