from os import path
print(path.relpath("/home/hpcadmin/lw/demo.py", start="/home/hpcadmin/lw")) # start可以指定路径
print(path.basename("/home/hpcadmin/lw/demo.py"))
"""返回
demo.py
"""
from os import path
print(path.relpath("/home/hpcadmin/lw/demo.py", start="/home/hpcadmin/lw")) # start可以指定路径
print(path.basename("/home/hpcadmin/lw/demo.py"))
"""返回
demo.py
"""
-------------------------------------------
个性签名:代码过万,键盘敲烂!!!
如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,博主在此感谢!