Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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
😄Bear
➖➖➖➖➖➖
🔘When we use bear as a noun, it's the animal’. As a verb, it has different meanings.
🔘Literally it can me 'to support weight'
🔜The bridge was designed to bear 100 tonnes.
🔘Figuratively, we can use it to mean 'to put up with' or 'to tolerate'
🔜The pain was too much to bear.
🔘 Another literal meaning of bear is 'to carry something' and we use this figuratively in the expression to bear in mind which means 'to think about' or 'to remember'.
🔜Bear in mind the deadline is today - you need to work quickly!
#Bear👨🏫@America
➖➖➖➖➖➖➖➖➖➖➖➖
🆕 Crypto News @Money
😁 Crypto Game @Egame
🇺🇸 US News @America
🇯🇵 Japan News @Japan
🇦🇪 UAE News @Dubai
▶️ Popular Movies @Videos
😜 Best Funny Video @Funnys
😄Bear
➖➖➖➖➖➖
🔘When we use bear as a noun, it's the animal’. As a verb, it has different meanings.
🔘Literally it can me 'to support weight'
🔜The bridge was designed to bear 100 tonnes.
🔘Figuratively, we can use it to mean 'to put up with' or 'to tolerate'
🔜The pain was too much to bear.
🔘 Another literal meaning of bear is 'to carry something' and we use this figuratively in the expression to bear in mind which means 'to think about' or 'to remember'.
🔜Bear in mind the deadline is today - you need to work quickly!
#Bear👨🏫@America
➖➖➖➖➖➖➖➖➖➖➖➖
🆕 Crypto News @Money
😁 Crypto Game @Egame
🇺🇸 US News @America
🇯🇵 Japan News @Japan
🇦🇪 UAE News @Dubai
▶️ Popular Movies @Videos
😜 Best Funny Video @Funnys