Source code for libka.utils.chop
#!/usr/bin/python3
# pylint: disable=line-too-long
# kate: space-indent on; indent-width 4; replace-tabs on; indent-mode python; remove-trailing-space modified;
# vim: expandtab ts=4
# pylint: enable=line-too-long
############################################################################
# Copyright © 2019 José Manuel Santamaría Lema <panfaust@gmail.com> #
# #
# This program is free software; you can redistribute it and/or modify #
# it under the terms of the GNU General Public License as published by #
# the Free Software Foundation; either version 2 of the License, or #
# (at your option) any later version. #
############################################################################
"""This module just provides a `simple_abort_handler` function to exit nice"""
[docs]
def rchop(string, ending):
"""
Removes the substring `ending` from the right of `string`.
"""
if string.endswith(ending):
result = string[:-len(ending)]
else:
result = string
return result
[docs]
def lchop(string, beginning):
"""
Removes the substring `beginning` from the left of `string`.
"""
if string.startswith(beginning):
result = string[len(beginning):-1]
else:
result = string
return result