Open file handles

pshell.open(file, mode='r', *, encoding=None, errors=None, compression='auto', **kwargs)

Open a file handle to target file name or file descriptor.

Unlike the builtin function, this wrapper performs automatic environment variable resolution in the file name and automatically logs the file access.

Parameters:
  • mode (str) – As in the builtin open() function. It always defaults to text mode unless ‘b’ is explicitly specified; unlike in gzip.open(), bz2.open(), and lzma.open() which instead default to binary mode.
  • encoding (str) – Character encoding when in text mode. Unlike the builtin open() function, it defaults to utf-8 instead of being platform-specific.
  • errors (str) – As in the builtin open() function, but it defaults to replace instead of strict.
  • compression

    One of:

    False
    No compression (use builtin open())
    ’gzip’
    gzip compression (use gzip.open())
    ’bzip2’:
    bzip2 compression (use bz2.open())
    ’lzma’:
    lzma compression (use lzma.open())
    ’auto’:
    Automatically set compression if the file extension is ‘.gz’, ‘.bz2’, or ‘.xz’
  • kwargs – Passed verbatim to the underlying open function