Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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
🤖A unique art exhibition Neuro Conflict will take place in Bali
📍 This weekend from 12 to 14 July, Superlative Gallery in Kuta will host an unusual exhibition called Neuro Conflict. Here you can experience a unique combination of art and modern technology, including neural networks.
🤖 The event will run for three days. The exhibition will feature works by international artists, interactive art installations, fascinating lectures on artificial intelligence, as well as performances and an auction.
@BaliNews
#wheretogo#exhibitions#Kuta
🧉Bali will host the official Arak Day tomorrow
🏝 Arak Day, the local palm vodka, is celebrated tomorrow, January 29.
ℹ️ Arak is a symbol of offering to the gods for a rich harvest, a form of gratitude.
📍 The official event will be held at GWK Park. The “Arak Berem Bali for the World” exhibition will also be held there.
🐲 The organizers of the celebration emphasize that Arak Day in Bali is not about drinking at all. Arak Day celebrations should be understood as a temple festival that is celebrated through prayer, not alcoholism.
@BaliNews
#holidays#events#exhibitions#culture