jacinle.cli.keyboard#

Uiltity functions to parse keyboard inputs.

Functions

maybe_mkdir(dirname)

Make a directory if it does not exist.

str2bool(s)

Convert a string to boolean value.

str2bool_long(s)

Convert a string to boolean value.

yes_or_no(question[, default])

Ask a yes/no question via input() and return their answer.

yn2bool(s)

Convert a string to boolean value.

Functions

maybe_mkdir(dirname)[source]#

Make a directory if it does not exist.

Parameters:

dirname – the directory to be created.

str2bool(s)[source]#

Convert a string to boolean value.

Parameters:

s (str) – the string to be converted.

Returns:

True if the string is “yes”, “true”, “y”, “t”, “1”; False if the string is “no”, “false”, “n”, “f”, “0”; otherwise, raise ValueError.

Return type:

bool

str2bool_long(s)[source]#

Convert a string to boolean value.

Parameters:

s (str) – the string to be converted.

Returns:

True if the string is “yes”, “true”; False if the string is “no”, “false”; otherwise, raise ValueError.

Return type:

bool

yes_or_no(question, default='yes')[source]#

Ask a yes/no question via input() and return their answer.

Parameters:
  • question (str) – the question to be asked.

  • default (str | None) – the default answer. It must be “yes” (the default), “no” or None (meaning that an answer is required from the user).

Return type:

bool

yn2bool(s)[source]#

Convert a string to boolean value.

Parameters:

s (str) – the string to be converted.

Returns:

True if the string is “y” or “yes”; False if the string is “n” or “no”; otherwise, raise ValueError.

Return type:

bool