亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

本文分享實(shí)例代碼主要在實(shí)現(xiàn)驗(yàn)證文件是否有讀寫權(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)證文件是否可讀寫代碼分享的全部?jī)?nèi)容,希望對(duì)大家有所幫助。感興趣的朋友可以繼續(xù)參閱本站:

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

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

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

相關(guān)文章

  • python將視頻轉(zhuǎn)換為全字符視頻

    python將視頻轉(zhuǎn)換為全字符視頻

    這篇文章主要為大家詳細(xì)介紹了Python將視頻轉(zhuǎn)換為全字符視頻,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-04-04
  • python實(shí)現(xiàn)Flappy Bird源碼

    python實(shí)現(xiàn)Flappy Bird源碼

    這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)Flappy Bird源碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-12-12
  • Python學(xué)習(xí)之迭代器的使用教程詳解

    Python學(xué)習(xí)之迭代器的使用教程詳解

    迭代器是一種對(duì)象,該對(duì)象包含值的可計(jì)數(shù)數(shù)字。從技術(shù)上講,在?Python?中,迭代器是實(shí)現(xiàn)迭代器協(xié)議的對(duì)象,它包含方法?iter()?和?next()。本文就來(lái)聊聊迭代器的具體使用吧
    2023-03-03
  • python list 切片倒著取的實(shí)現(xiàn)示例

    python list 切片倒著取的實(shí)現(xiàn)示例

    切片操作非常靈活,可以按照需要獲取列表中的任意一段元素,本文主要介紹了python list 切片倒著取的實(shí)現(xiàn)示例,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-01-01
  • 基于Python+tkinter實(shí)現(xiàn)簡(jiǎn)易計(jì)算器桌面軟件

    基于Python+tkinter實(shí)現(xiàn)簡(jiǎn)易計(jì)算器桌面軟件

    tkinter是Python的標(biāo)準(zhǔn)GUI庫(kù),對(duì)于初學(xué)者來(lái)說(shuō),它非常友好,因?yàn)樗峁┝舜罅康念A(yù)制部件,本文小編就來(lái)帶大家詳細(xì)一下如何利用tkinter制作一個(gè)簡(jiǎn)易計(jì)算器吧
    2023-09-09
  • kali中python版本的切換方法

    kali中python版本的切換方法

    今天小編就為大家分享一篇kali中python版本的切換方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-07-07
  • 深入了解Python中反射和動(dòng)態(tài)屬性的無(wú)限可能

    深入了解Python中反射和動(dòng)態(tài)屬性的無(wú)限可能

    理解 Python 中的反射和動(dòng)態(tài)屬性是編寫靈活和強(qiáng)大程序的關(guān)鍵,在這篇文章中,小編將帶領(lǐng)大家一起反射和動(dòng)態(tài)屬性的概念,并提供大量示例代碼,希望對(duì)大家有所幫助
    2023-11-11
  • django模板結(jié)構(gòu)優(yōu)化的方法

    django模板結(jié)構(gòu)優(yōu)化的方法

    這篇文章主要介紹了django模板結(jié)構(gòu)優(yōu)化的方法,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-02-02
  • Python callable函數(shù)使用方法詳解

    Python callable函數(shù)使用方法詳解

    這篇文章主要介紹了Python callable函數(shù)使用方法,一個(gè)可callable的對(duì)象是指可以被調(diào)用執(zhí)行的對(duì)象,并且可以傳入?yún)?shù), 用另一個(gè)簡(jiǎn)單的描述方式,只要可以在一個(gè)對(duì)象的后面使用小括號(hào)來(lái)執(zhí)行代碼,那么這個(gè)對(duì)象就是callable對(duì)象,下面來(lái)詳細(xì)介紹使用方法,需要的朋友可以參考下
    2024-10-10
  • Python實(shí)現(xiàn)刪除Android工程中的冗余字符串

    Python實(shí)現(xiàn)刪除Android工程中的冗余字符串

    這篇文章主要介紹了Python實(shí)現(xiàn)刪除Android工程中的冗余字符串,本文實(shí)現(xiàn)的是刪除Android資源(語(yǔ)言)國(guó)際化機(jī)制中的一些冗余字符串,需要的朋友可以參考下
    2015-01-01

最新評(píng)論