国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python驗證文件是否可讀寫代碼分享

2020-02-16 11:01:47
字體:
來源:轉載
供稿:網友

本文分享實例代碼主要在實現驗證文件是否有讀寫權限問題,具體如下:

# Import python libsimport osdef is_writeable(path, check_parent=False): ''' Check if a given path is writeable by the current user. :param path: The path to check :param check_parent: If the path to check does not exist, check for the   ability to write to the parent directory instead :returns: True or False ''' if os.access(path, os.F_OK) and os.access(path, os.W_OK):  # The path exists and is writeable  return True if os.access(path, os.F_OK) and not os.access(path, os.W_OK):  # The path exists and is not writeable  return False # The path does not exists or is not writeable if check_parent is False:  # We're not allowed to check the parent directory of the provided path  return False # Lets get the parent directory of the provided path parent_dir = os.path.dirname(path) if not os.access(parent_dir, os.F_OK):  # Parent directory does not exit  return False # Finally, return if we're allowed to write in the parent directory of the # provided path return os.access(parent_dir, os.W_OK)def is_readable(path): ''' Check if a given path is readable by the current user. :param path: The path to check :returns: True or False ''' if os.access(path, os.F_OK) and os.access(path, os.R_OK):  # The path exists and is readable  return True # The path does not exist return False

總結

以上就是本文關于Python驗證文件是否可讀寫代碼分享的全部內容,希望對大家有所幫助。感興趣的朋友可以繼續參閱本站:

Python文件操作基本流程代碼實例

Python實現讀取txt文件并畫三維圖簡單代碼示例

如有不足之處,歡迎留言指出。感謝朋友們對本站的支持!

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 电白县| 前郭尔| 盐池县| 尖扎县| 静安区| 东海县| 文水县| 阿拉善盟| 洛南县| 双辽市| 阿拉善左旗| 密山市| 峨边| 八宿县| 曲沃县| 渝北区| 望江县| 泾川县| 苏尼特右旗| 南丹县| 湖南省| 石河子市| 大港区| 竹北市| 拉萨市| 潼关县| 翼城县| 昂仁县| 黄石市| 潼南县| 西乌珠穆沁旗| 安国市| 商丘市| 连山| 大安市| 新晃| 磐石市| 卢氏县| 工布江达县| 南丰县| 黔西县|