Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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
🌍🌍✨✨✨✨#tv
🔴Yangiliklar
🇺🇿Oltiariq tumanida 🌱“Yashil makon” loyihasi doirasida Tuman Madaniyat boʻlimi xodimlari ishtirokida ko‘chat ekish ishlari amalga oshirildi.
Rasmiy sahifalarimizda bizni kuzatib boring:👇
📱Telegram | 📱Instagram |
📱Facebook | 📱YouTube
📺Smart TV Owners Want Multi-Device Viewing Options
Smart TV Owners watch a combination of both broadcast and online #TV. Further exploring their diverse TV engagement habits shows they frequently ventures beyond their smart TVs, watching their favorite TV shows and films across a broad range of devices, demonstrating that it’s the content, not the device, that governs preferences.
🚀@PerspectiveIX
🌀 http://prs.pctvix.co/TelegramIX