Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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
There’s a bird that smells like manure. The hoatzin, a bird found in the Amazon rainforest, has earned the nickname “the stinkbird.” Its digestive system ferments leaves the way cows digest grass, producing a strong manure-like smell. Because of this, predators often avoid it—not because it’s dangerous, but because it smells terrible.
@googlefactss#birds
[read more....]
The Argentine lake duck (Oxyura vittata) holds the record for the longest penis of any vertebrate relative to its body size. Males possess a corkscrew-shaped, spiny, and often-retracted organ that can measure up to 20 cm (nearly 8 inches).
@googlefactss#birds