Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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
🛍DEX aggregator from the TON Diamonds team
The team launched their Mini App of Dex Diamonds and updated the interface, now it is much more convenient and faster to “swap” tokens directly from #telegram, receiving #cashback in tokens for it ✨#GLINT.
#TonDiamondsDex achieved an impressive result — more than 100,000 transactions, and a trading turnover of $50 million, and this was achieved in 8 months.
Now there are several aggregators in the TON arena that provide a similar service. Let's see who comes out ahead!
DexDiamondsBot | Channel