jacinle.io.common#

Functions

auto_close(file)

A context manager that automatically closes the file.

fsize_format(num)

Human-readable file size.

get_ext(fname[, match_first])

Get the extension of a file name.

Functions

auto_close(file)[source]#

A context manager that automatically closes the file.

fsize_format(num)[source]#

Human-readable file size.

Examples

>>> fsize_format(0)
'0 bytes'
>>> fsize_format(1024)
'1 kB'

Source: https://stackoverflow.com/questions/1094841/reusable-library-to-get-human-readable-version-of-file-size

get_ext(fname, match_first=False)[source]#

Get the extension of a file name.

Parameters:
  • fname (str) – the file name.

  • match_first (bool) – if True, match the left-most “.”.