日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

【Python】内置os.path模块最常用的一些用法

發布時間:2025/3/15 python 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Python】内置os.path模块最常用的一些用法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

os.path模塊主要用于文件的屬性獲取,在編程中經常用到,以下是該模塊的幾種常用方法。
更多的方法可以去查看官方文檔:http://docs.python.org/library/os.path.html

# -*- coding:utf-8 -*- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' #作者:cacho_37967865 #博客:https://blog.csdn.net/sinat_37967865 #文件:os_path_model.py #日期:2020-04-11 #備注:os.path 模塊主要用于獲取文件的屬性。 ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' import osdef deal_path():file = 'E:\zenglingwei\\test\pic\\test.jpg'print('返回絕對路徑-->',os.path.abspath(file)) # E:\zenglingwei\test\pic\1.jpgprint('返回path的真實路徑-->', os.path.realpath(file)) # E:\zenglingwei\test\pic\1.jpgprint('返回元組-->',os.path.split(file)) # ('E:\\zenglingwei\\test\\pic', '1.jpg')print('返回文件路徑-->',os.path.dirname(file)) # E:\zenglingwei\test\picprint('返回文件名-->', os.path.basename(file)) # 1.jpgprint('返回正確、錯誤-->', os.path.exists(file)) # Trueprint('返回文件大小-->', os.path.getsize(file)) # 653803b 如果文件不存在就返回錯誤print('返回最近訪問時間-->',os.path.getatime(file)) # 1586593521.9310188print('返回文件創建時間-->',os.path.getctime(file)) # 1586593521.9310188print('返回最近修改時間-->',os.path.getmtime(file)) # 1586593521.9310188print('合并絕對路徑-->',os.path.join(os.path.dirname(file),os.path.basename(file))) # E:\zenglingwei\test\pic\1.jpgprint('合并絕對路徑-->', os.path.join('data','logs','test')) # data\logs\testif __name__ == '__main__':deal_path()

?

總結

以上是生活随笔為你收集整理的【Python】内置os.path模块最常用的一些用法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。