假设我有a = "C:\\folder1\\folder2\\picture.jpg"
如何将变量b分配给文件名及其扩展名:b ='picture.jpg'
Without too many complications, you can just use the os
module as follows:
import os
a = "C:\folder1\folder2\picture.jpg"
b = os.path.basename(a)
Which will output what you desire: 'picture.jpg'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.