validate_initial

pyrcs.utils.validate_initial(x, as_is=False)[source]

Validates if a string is a single letter, returning it in upper case or as is.

Parameters:
  • x (str) – The input value to validate, which is expected to be a string representing a single letter.

  • as_is (bool) – If set to True, the function returns the letter in its original case; if set to False (default), the letter is returned in uppercase.

Returns:

The validated initial letter, either in uppercase or as-is.

Return type:

str

Examples:

>>> from pyrcs.utils import validate_initial
>>> validate_initial('x')
'X'
>>> validate_initial('x', as_is=True)
'x'
>>> validate_initial('xyz')
AssertionError: `x` must be a single letter.