最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python驗(yàn)證文件是否可讀寫(xiě)代碼分享

 更新時(shí)間:2017年12月11日 09:46:35   作者:張宋付  
這篇文章主要介紹了Python驗(yàn)證文件是否可讀寫(xiě)代碼分享,具有一定借鑒價(jià)值,需要的朋友可以參考下。

本文分享實(shí)例代碼主要在實(shí)現(xiàn)驗(yàn)證文件是否有讀寫(xiě)權(quán)限問(wèn)題,具體如下:

# Import python libs
import os
def 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

總結(jié)

以上就是本文關(guān)于Python驗(yàn)證文件是否可讀寫(xiě)代碼分享的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:

Python文件操作基本流程代碼實(shí)例

Python實(shí)現(xiàn)讀取txt文件并畫(huà)三維圖簡(jiǎn)單代碼示例

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

相關(guān)文章

最新評(píng)論

山阴县| 秦安县| 宣威市| 景德镇市| 抚顺市| 辽阳市| 德清县| 澜沧| 万全县| 泾阳县| 高邮市| 新泰市| 阿城市| 阜康市| 和林格尔县| 靖西县| 黑山县| 佛坪县| 乐东| 隆化县| 楚雄市| 印江| 尼勒克县| 正宁县| 贺州市| 高阳县| 凌云县| 双鸭山市| 绥德县| 沙田区| 库车县| 盐津县| 札达县| 金坛市| 大方县| 尉氏县| 普兰县| 淮滨县| 韶山市| 八宿县| 郁南县|