Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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
This chat is all about kobolds and those who love them, and also own them!~ if you like those little mischievous things then you better hop in and start loving on them!~
#Chat
#Partner
https://t.me/joinchat/f7PyhKiPzrE1MGEx
Do you like beefy bois? Wanna get squeezed by some swole buff guy? Then maybe stop by this channel and oggle at all these muscled studs~
#Channel
#Partner
@snookmusclescorner
This chat is all about kobolds and those who love them, and also own them!~ if you like those little mischievous things then you better hop in and start loving on them!~
#Chat
#Partner
#NSFW
https://t.me/joinchat/f7PyhKiPzrE1MGEx
#MoveWith#Live#Workout#Partner
Join the MoveWith: Live Workout Partner beta on ✈️#TestFlight
🔗 Link: https://testflight.apple.com/join/uEXQqJ2V
Shared by Dimitri