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
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.