早睡早起,方能养生
Sleep early rise early, way to keep healthy

Python获取图片、文件路径中的名字,不含后缀

super
2022-12-15 00:10
views 3300

Python获取图片、文件路径中的名字 或 后缀

 

img = 'https://rongsp.com/static/super/images/lo123#@!&#!@..1239083123go.png'

img_info_array = img.split("/")

local_img_name = img_info_array[-1]

# 解析图片格式
name_info = local_img_name.split(".")
suffix = name_info[-1]
suffix_len = len(suffix) + 1
prefix = local_img_name[0:-suffix_len]

print(local_img_name)
# lo123#@!&#!@..1239083123go.png

print(prefix)
# lo123#@!&#!@..1239083123go

print(suffix)
# png

 



分享
0 条讨论
top