seekable()
The `seekable()` method checks if a file object supports random access, meaning you can move the file pointer to a different location. It returns True if seeking is supported and False if not, such as for non-seekable objects like certain network streams.
file_object.seekable()
Returns ( Boolean )True or False. If the file is seekable then it returns True. Otherwise False
fob=open('data.txt','r')
print(fob.seekable()) # True
fob.close()
fob=open('data.txt','w')
print(fob.seekable()) # True
fob.close()
fob=open('data.txt','+r')
print(fob.seekable()) # True
fob.close()
import sys
print(sys.stdin.seekable()) # False
fob = open('data.txt', 'r')
if fob.seekable():
fob.seek(10) # Move pointer to 10th byte
fob.close()
with open('data.txt', 'r') as f:
print(f.seekable()) # Output: True
with open('data.txt', 'rb') as f:
print(f.seekable()) # Output: True
import sys
print(sys.stdin.seekable()) # Output: False
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.