Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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
The Milan Trade Fair Rho-Pero, Italy.
Salone del Mobile 2022 is taking place in Milan until June 12th.
The central element of the design of the Milan Trade Fair Rho-Pero, Italy, is a glass and steel structure that runs like a giant ribbon, caressing the large and small-scale building along its path and ending into a huge crater-like vortex.
The structure covers a raised walkway, flanked either side by eight giant exhibition halls. Nestling between them are a variety of smaller structures containing bars, restaurants and shops.
Architecture: Fucsas
Photos: Ramon Prat
#fuksas#fuksasarchitects#arch_shovel#architecture#milano#milan#italy#trade#fair#design#architecturephotography