0
我想查看是否存在像test_100.webp這樣的文件,然後查看文件test.yaml。因此,我需要從最後去除「_100.webp」模式。我試圖使用下面的代碼,它給我的問題。從字符串末尾剝離圖案
for 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')
哪些問題是什麼呢? – 2013-05-04 07:09:27
嘗試'image_strip = image.replace('_ 100.webp','')' – 2013-05-04 07:14:12
基本上它也從字符串中刪除其他字符的其他出現。如果使用image.rstrip(「_ 100.webp」),則200_100.webp將減少爲2。 – vkaul11 2013-05-04 07:18:10