file_path#

gwpy.io.utils.file_path(fobj: NamedReadable | bytes | CacheEntry) str[source]#

Determine the path of a file.

This doesn’t do any sanity checking to check that the file actually exists, or is readable.

Parameters:
fobjfile, str, os.PathLike, bytes, CacheEntry, …

The file object or path to parse.

Returns:
pathstr

The path of the underlying file, always as a str.

Raises:
ValueError

If a file path cannnot be determined.

Examples

>>> from gwpy.io.utils import file_path
>>> import pathlib
>>> file_path("test.txt")
'test.txt'
>>> file_path(pathlib.Path('dir') / 'test.txt')
'dir/test.txt'
>>> file_path(open("test.txt", "r"))
'test.txt'
>>> file_path("file:///home/user/test.txt")
'/home/user/test.txt'