neclib.core.files.general#

General file operations.

This module provides general file operations, not limited to a specific file format or method to access the file system.

read(__path, /, *, allow_remote=True)[source]#

Read a file, if it’s accessible via any available way.

Parameters:
  • __path (Union[PathLike, str, IO]) – The file path.

  • allow_remote (bool) – If True the file can be fetched from remote host, otherwise the look-up is limited to local file system.

Returns:

The file content.

Return type:

content

Raises:
  • FileNotFoundError – If the file couldn’t be found.

  • URLError – If the protocol (http, https, ftp, etc.) is specified in __path but invalid.

Examples

>>> neclib.core.files.read("relative/path/to/local-file.txt")
>>> neclib.core.files.read("/absolute/path/to/local-file.txt")
>>> neclib.core.files.read("https://example.com/file.txt")
>>> neclib.core.files.read("http://192.168.xxx.xxx:80/file.txt")