python - stripping a pattern from the end of the string -
i want see if file test_100.webp exists , @ file test.yaml. therefore, need strip pattern "_100.webp" end. tried use code below , giving me issues.
i, image in enumerate(images_in_item): if image.endswith("_100.webp"): image_strip = image.rstrip(_100.webp) snapshot_markup = os.path.join(image_strip + 'yaml')
do this:
suffix = '_100.webp' if image.endswith(suffix): image_strip = image[:-len(suffix)] snapshot_markup = os.path.join(image_strip + 'yaml')
Comments
Post a Comment