Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в Python есть функция os.access()
Проверять так:
os.access(path, flag)
Функция вернёт bool в зависимости от наличия указанного флага.
Всего есть 4 флага проверки:
os.F_OK - наличие файла на диске
os.R_OK - доступ на чтение
os.W_OK - доступ на запись
os.X_OK - доступ на исполнение
Например, вместо try-except лучше делать так (пример из документации):
if os.access("myfile", os.R_OK):
with open("myfile") as fp:
return fp.read()
#basic#libs
That's my global popstar right there..
For me, Jungkook has the best vocals in the K-pop industry. His voice always shocks me—how can a human being have such a perfect voice? And fun fact: he always sounds exactly like the studio version whenever he sings on Weverse Live. He always strives for perfection; even while dancing, he sounds amazing.
I am really proud to be a fan of Jungkook and BTS.💜
#jungkook | #editvideo
@letjungcook70
happy birthday to Jungkook🎂Wishing you health, happiness, and everything you’ve been dreaming of this year.🥳, the golden maknae! You’re the sparkle in my life🫶💫😍
#jungkook | #editvideo | #HBD_EDIT
@letjungcook70