reformat_string

hhpy.main.reformat_string(string: str, case: Optional[str] = 'lower', replace: Optional[Mapping[str, str]] = None, lstrip: Optional[str] = ' ', rstrip: Optional[str] = ' ', demojize: bool = True, trans: bool = False, trans_dest: Optional[str] = 'en', trans_src: Optional[str] = 'auto', trans_sleep: Union[float, bool] = 0.4, warn: bool = True) → str[source]

Function to quickly reformat a string to a specific convention. The default convention is only lowercase, numbers and underscores. Also allows translation if optional dependency googletrans is installed.

Parameters:
  • string – input string to be reformatted
  • case – casts string to specified case, one of [‘lower’, ‘upper’] [optional]
  • replace – Dictionary containing the replacements to be made passed to re.sub . Defaults to replacing any non [a-zA-Z0-9] string with ‘_’. Note that this means that special characters from other languages get replaced. If you don’t want that set replace to False or specify your own mapping. Is applied last so make sure your conventions match [optional]
  • lstrip – The leading characters to be removed, passed to string.lstrip [optional]
  • rstrip – The training characters to be removed, passed to string.rstrip [optional]
  • demojize – Whether to remove emojis using emoji.demojize [optional]
  • trans – Whether to translate the string using googletrans.Translator.translate [optional]
  • trans_dest – The language to translate from, passed to googletrans as dest=trans_dest [optional]
  • trans_src – The language to translate to, passed to googletrans as src=trans_src [optional]
  • trans_sleep – Amount of seconds to sleep before translating, should be at least .4 to avoid triggering google’s rate limits. Set it to lower values / None / False for a speedup at your own risk [optional]
  • warn – Whether to show UserWarnings triggered by this function. Set to False to suppress, other warnings will still be triggered [optional]
Returns:

reformatted string