Python remove suffix

12 Python code examples are found related to " remove suffix". You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.
Example 1
Source File: util.py    From aerospike-admin with Apache License 2.0 5 votes vote down vote up
def remove_suffix(input_string, suffix):
    """
    Simple function to remove suffix from input_string if available
    """

    try:
        input_string = input_string.strip()
        if not input_string.endswith(suffix):
            return input_string
        return input_string[0: input_string.rfind(suffix)]
    except Exception:
        return input_string 
Example 2
Source File: hinted-mods.py    From NUITKA-Utilities with MIT License 5 votes vote down vote up
def remove_suffix(mod_dir, mod_name):
    if mod_name not in mod_dir:
        return mod_dir
    l = len(mod_name)
    p = mod_dir.find(mod_name) + l
    return mod_dir[:p] 
Example 3
Source File: bingo.py    From pajbot with MIT License 5 votes vote down vote up
def remove_emotes_suffix(word):
    match = remove_emotes_suffix_regex.match(word)
    if not match:
        # the regex has a .* in it which means it should match anything O_o
        raise ValueError("That doesn't match my regex O_o")

    return match.group(1) 
Example 4
Source File: globals.py    From plugin.video.netflix with MIT License 5 votes vote down vote up
def remove_ver_suffix(version):
        """Remove the codename suffix from version value"""
        import re
        pattern = re.compile(r'\+\w+\.\d$')  # Example: +matrix.1
        return re.sub(pattern, '', version)


# pylint: disable=invalid-name
# This will have no effect most of the time, as it doesn't seem to be executed
# on subsequent addon invocations when reuseLanguageInvoker is being used.
# We initialize an empty instance so the instance is importable from run_addon.py
# and run_service.py, where g.init_globals(sys.argv) MUST be called before doing
# anything else (even BEFORE OTHER IMPORTS from this addon) 
Example 5
Source File: Duplicate Glyph with Component.py    From Glyphs-Scripts with Apache License 2.0 5 votes vote down vote up
def removeSuffix(glyphName):
	try:
		if glyphName[-4] == "." and glyphName[-3:].isdigit:
			return glyphName[:-4]
	except:
		return glyphName 
Example 6
Source File: metadata.py    From blobxfer with MIT License 5 votes vote down vote up
def remove_vectored_io_slice_suffix_from_name(name, slice):
    # type: (str, int) -> str
    """Remove vectored io (stripe) slice suffix from a given name
    :param str name: entity name
    :param int slice: slice num
    :rtype: str
    :return: name without suffix
    """
    suffix = '.bxslice-{}'.format(slice)
    if name.endswith(suffix):
        return name[:-len(suffix)]
    else:
        return name 
Example 7
Source File: util.py    From webfont-generator with MIT License 5 votes vote down vote up
def remove_suffix(s, suffix):
    was_there = s.endswith(suffix)
    if was_there:
        s = s[:-len(suffix)]
    return s, was_there 
Example 8
Source File: pointer_net_helper.py    From PointerSQL with MIT License 5 votes vote down vote up
def remove_end_suffix(self, sentence):
    result = []
    for x in sentence:
      if x == Vocabulary.END_TOK:
        result.append(x)
        break
      else:
        result.append(x)
    return result 
Example 9
Source File: symbolize.py    From language-resources with Apache License 2.0 5 votes vote down vote up
def RemoveSuffix(string, suffix):
  if string.endswith(suffix):
    return string[:-len(suffix)]
  else:
    return string 
Example 10
Source File: transform_suffixes.py    From PIE with MIT License 5 votes vote down vote up
def remove_suffix(word, suffix):

    if len(suffix) > len(word):
        print("suffix: {} to be removed has larger length than word: {}".format(suffix, word))
        return word

    l = len(suffix)

    if word[-l:] == suffix:
        return word[:-l]
    else:
        print("**** WARNING: SUFFIX : {} NOT PRESENT in WORD: {} ****".format(suffix, word))
        return word 
Example 11
Source File: utils.py    From coach with Apache License 2.0 5 votes vote down vote up
def remove_suffix(name, suffix_start):
    for s in suffix_start:
        split = name.find(s)
        if split != -1:
            name = name[:split]
            return name 
Example 12
Source File: file_utils.py    From nucleus7 with Mozilla Public License 2.0 3 votes vote down vote up
def remove_suffix(path: str, suffix: Union[str, None]) -> str:
    """
    Remove the suffix from the path if file name without extension ends with it

    Parameters
    ----------
    path
        name with prefix
    suffix
        suffix to remove

    Returns
    -------
    name_without_suffix
        name with removed suffix

    """
    if not suffix:
        return path
    directory, basename = os.path.split(path)
    basename, ext = os.path.splitext(basename)
    if basename.endswith(suffix):
        word_split = basename.rsplit(suffix, 1)
        basename = "".join(word_split[:-1])
        path = os.path.join(directory, basename + ext)
    return path