Как правильно проверить атрибуты доступа файла? То есть доступна ли запись в файл или является ли он исполняемым?
Для этого в 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
Caramelized Shallots Pumpkin Pasta 🎃🍝
Recipe for 2 servings
Ingredients:
- 1/2 Hokkaido pumpkin 🎃
- 250 g pasta 🍝
- 250 g shallots 🧅
- Vegan butter for frying 🧈
- 25 ml maple syrup 🍁
- 100 g vegan cream cheese 🌱
- 300 ml vegetable stock 🥕🍲
- Pinch of salt and pepper 🧂
Toppings
- Parsley, chopped 🌿
Preparation:
1. Dice the pumpkin and blanch for 10 minutes 🍲
2. Cook the pasta 🍝
3. Fry the shallots in butter, add maple syrup for a caramelized touch 🍁🧅
4. Deglaze with vegetable stock, add the pumpkin, stir, and simmer briefly 🎃🍲
5. Stir in the cream cheese, then mix in the pasta 🌱🍝
6. Top with fresh parsley and enjoy! 🌿✨
#VeganPasta#PumpkinSeason#CaramelizedShallots#ComfortFood#FallRecipes#PlantBased#EasyMeals#Yummy#PastaNight
@dishes