Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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 Toronto HongKonger Dragon Boat team is now recruiting.
About the team:
We stand with HongKongers. Our goal is to regain HongKongers’ energy in Toronto and maintain our Lion Rock spirits high and strong in Canada through dragon boat racing, spreading the name of 'HongKongers' to more people.
coach – Matthew Ma:
👉🏻10 years of experience
👉🏻8 years as a certified dragon boat coach.
👉🏻was a part of the national team that represented Canada in the 13th and 14th World Dragon Boat Racing Championships in China and Thailand.
Facebook: https://www.facebook.com/profile.php?id=61554437804498&mibextid=LQQJ4d
Instagram: https://www.instagram.com/tohkdbt?igsh=MXF1NXRhMWdxYjEwcQ==
Email: [email protected]
Application: form at https://forms.gle/7HS5Uao5xFQd9isUA
#hongkonger#toronto#torontohongkonger
#drangonboatteam
#dragonboatrecruitment