mirror of
https://github.com/wassname/segpy.git
synced 2026-07-12 13:26:42 +08:00
24 lines
516 B
Python
24 lines
516 B
Python
import os
|
|
|
|
|
|
def seekable(fh):
|
|
"""Determine whether a file-like object supports seeking.
|
|
|
|
Args:
|
|
fh: The file-like-object to be tested.
|
|
|
|
Returns:
|
|
True if the file supports seeking, otherwise False.
|
|
"""
|
|
try:
|
|
return fh.seekable()
|
|
except AttributeError:
|
|
try:
|
|
pos = fh.tell()
|
|
try:
|
|
fh.seek(0, os.SEEK_END)
|
|
finally:
|
|
fh.seek(pos)
|
|
except AttributeError:
|
|
return False
|
|
return True |