text module — py-utilities 0.0.1 documentation

# text module

## csv_utilities

`py_utilities.text.csv_utilities.` `csv_to_html`(file_path, has_headers=None, delimiters=[',', ';'])

  Writes csv instream as html outstream

`py_utilities.text.csv_utilities.` `list_to_csv`(file_path, data_as_list, delimiter=', ', quoting=1)

  Writes data_as_list into a csv file at file_path

## string_utilities

`py_utilities.text.string_utilities.` `ascii_to_str`(ascii_list)

  Returns a string from a list of ascii values

      >>> ascii_to_str([104, 101, 108, 108, 111])
      'hello'

      >>> ascii_to_str([82, 121, 97, 110])
      'Ryan'

`py_utilities.text.string_utilities.` `random_string`(length=16, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789')

  Returns a random string of size length

      >>> test = random_string()

      >>> len(test)
      16

`py_utilities.text.string_utilities.` `str_to_ascii`(str)

  Returns a list of ascii values from a string

      >>> str_to_ascii('hello, world')
      [104, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100]

      >>> str_to_ascii('Ryan')
      [82, 121, 97, 110]

`py_utilities.text.string_utilities.` `str_to_bool`(str_val)

  Returns True if str_val is in (“yes”, “y”, “true”, “t”, “1”), False if str_val is in (“no”, “n”, “false”, “f”, “0”, “0.0”, “”, “none”, “[]”, “{}”), and ValueError otherwise.

`py_utilities.text.string_utilities.` `strip_punctuations`(str)

  Returns string stripped of punctuations

      >>> strip_punctuations("asdfs. asdfasdf. asdfsaf? sadfasf!")
      'asdfs asdfasdf asdfsaf sadfasf'

      >>> strip_punctuations("asdfs.....asdfasdf. asdfsaf? sadfasf!")
      'asdfsasdfasdf asdfsaf sadfasf'

      >>> strip_punctuations("")
      ''

`py_utilities.text.string_utilities.` `truncate`(str, length, trailing_chars='...')

  Returns a truncated str of length with a trailing ‘...’

      >>> truncate('foobar', 3)
      'foo...'

      >>> truncate('foobar', 1)
      'f...'

      >>> truncate('', 1)
      ''

      >>> truncate('hello', 100)
      'hello'

## text_utilities

`py_utilities.text.text_utilities.` `find_ips`(text)

  Returns a list of all ip addresses in text

      >>> test_ips = "192.123.23.12 32.23.2.2 fasfafa"

      >>> find_ips(test_ips)
      ['192.123.23.12', '32.23.2.2']

      >>> test_no_ips = "asdjfkalsdjf sdkfjaksd aksdfjasdf asdfsdf"

      >>> find_ips(test_no_ips)
      []

`py_utilities.text.text_utilities.` `lines`(file_path, strip=True)

  Returns a list of lines from file_path

`py_utilities.text.text_utilities.` `strip_if_true`(text, strip)

  Strips text if strip is True

`py_utilities.text.text_utilities.` `wrap`(text, width=70, **kwargs)

  Returns wrapped text

      >>> test = '12345\n 12345\n 12345\n 12345\n'

      >>> wrap(test, width=3)
      '123\n45\n123\n45\n123\n45\n123\n45'