Text Functions

betterfunctions.textfunctions.count_lines(directory=None, *, count_empty_lines=True, include_hidden=False, ignored_dirs=None, ignored_files=None)

Counts the total amount of lines in all Python files in the given directory.

Parameters:
  • directory (str | None) – The directory to count the lines in. Defaults to the current working directory.

  • count_empty_lines (bool) – Whether to count empty lines. Defaults to True.

  • include_hidden (bool) – Whether to include directories starting with a dot. Defaults to False.

  • ignored_dirs (list[str] | None) – A list of directories to ignore. By default, venv folders and folders starting with a dot are ignored.

  • ignored_files (list[str] | None) – A list of file patterns to ignore.

Return type:

int

betterfunctions.textfunctions.remove_punctuation(text)

Removes punctuation from a given string.

Parameters:

text (str) – The string, whom you want to remove the punctuation from.

Return type:

str

betterfunctions.textfunctions.replace_substring(text, old, new)

Replaces a substring with a new text.

Parameters:
  • text (str) – The string where the substring is in.

  • old (str) – The old substring.

  • new (str) – The new content of the substring.

Return type:

str

betterfunctions.textfunctions.reverse_string(s)

Reverses a given string.

Parameters:

s (str) – The string which should be reversed.

Return type:

str

betterfunctions.textfunctions.to_camel_case(text)

Converts a string to camelcase.

Parameters:

text (str) – The string which should be converted.

Return type:

str

betterfunctions.textfunctions.to_snake_case(text)

Converts a string to snake case.

Parameters:

text (str) – The string which should be converted.

Return type:

str

betterfunctions.textfunctions.word_count(text)

Counts the words in a given string.

Parameters:

text (str) – The string used to count the words.

Return type:

int