Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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
Curated Crypto | ꘜ
🤑WTF: ETH options open interest just hit a 1.5-year high!
Degens are loading up on longs, while whales are stacking ETH at all-time record pace!
But hedge funds are going mega short - CME ETH futures short positioning just keeps smashing new records!
Green But Red in real life!
#WTF
The suspect attempted to escape an interrogation room by breaking through the wall while no one was watching—only to be caught shortly after.
@Viral_Today / #wtf
Imagine a coffee table that moves around the house by itself—well, you don’t have to anymore because it’s real. It’s just as fascinating as it is creepy.
@Viral_Today / #wtf