Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的变量有这样的名字:
var1 = '/home/name/file.txt'
如何在变量中获取文件名?
我需要这样的变量:
var1 = 'file.txt'
>>> import os >>> os.path.basename('/home/name/file.txt') 'file.txt'