欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Python os模块获取路径中的路径、文件名与扩展名,或者获取http链接的路径、文件名与扩展名

程序员文章站 2022-05-12 15:05:35
...
file_Path = "/home/l/my/test.py"
path,temp = os.path.split(file_Path)
file_name,extension = os.path.splitext(temp)
print('path:',path)
print('file_name:',file_name)
print('extension:',extension)

输出

path: /home/l/my
file_name: test
extension: .py
http_Path = "https://lns.hywly.com/a/1/34533/103.jpg" #这个链接有惊喜哦
path,temp = os.path.split(http_Path)
file_name,extension = os.path.splitext(temp)
print('path:',path)
print('file_name:',file_name)
print('extension:',extension)

输出

path: https://lns.hywly.com/a/1/34533
file_name: 103
extension: .jpg