Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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
Switch operatori
Tanlash operatori bizga bir nechta qiymatlardan, o’zgaruvchilarga to’g’ri keluvchi qiymatni tanlashda va uni ishga tushirishda ishlatiladi. Misol uchun, hafta kunlarini raqamidan topish topshiriq sifatida berildi. Ularni bemalol topishimiz mumkin, lekin kompyuterga uni qanday tushuntiramiz?
👉Batafsil
👨🏫 Mentor: Suxrob Xayitmurodov
#csharp#switch#choice#starter
.NET Uzbekistan Community
__________
Telegram | Instagram | Youtube
@QuanBot
Qué puede hacer este bot?
Este es un bot avanzado para crear encuestas, agregar opciones y usar muchas herramientas.
Idioma: Múltiple
(visto en @BotsGram_cu)
#group, #questions, #template, #poll, #publish, #choice, #inline, #community, #management, #administration, #voting, #vote, #votes, #survey
@ultimate_pollbot
Qué puede hacer este bot?
Este bot es un robot de votación y encuestas definitivo para crear, compartir y evaluar encuestas dentro de Telegram 🔎
Idioma: Inglés
(visto en @BotsGram.cu)
#choice, #forum, #comment, #inline, #community, #management, #administration, #groups, #vote, #votes, #poll, #decide, #decision, #question, #survey