Что-то вы гоните насчет "привычного вида формата 755 и 644". Я вот вообще не понял что это!😳
Действительно, что означают цифры которые мы получили в прошлом посте?
Это кодировка, заключающая в себе режимы доступа к файлу.
Подробней можно почитать в статье про chmod.
Там можно увидеть альтернативное обозначение того же самого с помощью символов r w x, что значит чтение, запись, исполнение.
Чтобы преобразовать восьмеричное число в такое обозначение в Python есть готовая функция
>>> stat.filemode(0o755)
'?rwxr-xr-x'
Мы видим 3 группы по 3 символа, дающие 3 типа доступа для 3 типов юзеров.
А что за знак вопроса в начале?
Давайте передадим в эту функцию необрезанное значение от os.stat
>>> stat.filemode(os.stat(path).st_mode)
'drwxr-xr-x'
Это данные, которые мы безжалостно обрезали в прошлый раз😼
Первый символ обозначает тип объекта. Это может быть файл (-), директория (d) или симлинк (l).
Вот простая схема данной кодировки
[1][3][3][3]
│ │ │ │
│ │ │ └──> Others Permissions
│ │ └─────> Group Permissions
│ └────────> Owner Permissions
└───────────> File Type
(разверните экран если вы с телефона)
Если вы попробуете получить пермишены для симлинка то получите пермишены для файла
>>> path = '.venv/bin/python3'
>>> stat.filemode(os.stat(path).st_mode)
'-rwxr-xr-x'
Чтобы получить свойства именно симлинка, нужно это явно указать
>>> stat.filemode(os.stat(path, follow_symlinks=False).st_mode)
'lrwxrwxrwx'
#tricks#basic
#SayYesToWasteLess by bringing our own clean containers and saying no to disposables. Every little action, even if seemingly insignificant, can have an impact on our Earth. Learn more about what climate actions you can take here: www.mewr.gov.sg/climateaction#BringYourOwn
Getting busy this holiday season? Don’t forget to keep your habits sustainable! Bring your tote for shopping, your lunchbox & cutlery for takeaway meals, and reusable plates for gatherings.
#BringYourOwn#TowardsZeroWaste#SayYEStoWasteLess
Heading out to tabao your next meal? Don’t forget to #BringYourOwn reusables! Let’s #SupportOurHawkers and reduce waste by bringing our own containers 😊
Ready for takeaway feasts?
This holiday season, let's switch to reusable containers and cut down on disposables!
#SayYEStoWasteLess#TowardsZeroWaste#BringYourOwn#BYO
It’s always good to pack reusable containers in your bag because you never know when cravings may strike! #BringYourOwn😊
Have other ideas on zero waste? Share it on social media this #YED2020, so that we can motivate more people to move #TowardsZeroWaste! www.cgs.gov.sg/yed
Santa’s not the only one with a reusable bag!
When visiting the mall to shop, let’s bring our reusable bags. Together, we can ensure fa-la-la-la-la, la-la-la-less packaging waste. 🛍️
#SayYEStoWasteLess#TowardsZeroWaste#BringYourOwn#BYO#BYOB
Only sit on seats without markings when dining in at #OurHawkerCentres to maintain #SafeDistancing. If the seating capacity is limited, #BringYourOwn clean containers and choose to take-out instead. Let’s unite to #FightCOVID19 together! 💪#SGUnited
Our 2023 Wrapped is in!
'Bringing Your Reusable Bag for Shopping' is the chart-topping single we all need.
From reusable essentials to recycling mastery, we've built an eco-habit playlist that's pure chart green. Top tracks include 'Reusable Bag Groove', 'Recycling Rhythm', and 'Energy-Saving Melody'.
Fellow eco-warriors, let’s keep this #SustainableSG chart-topper habit going strong!
#TowardsZeroWaste#BYOB#BringYourOwnBag#BringYourOwn#BYO#3Rs#Reduce#Reuse#Recycle#EnergyEfficiency