Первая директория в sys.path
🔸 Когда вы запускаете Python-интерпретатор в интерактивном режиме, в системные пути (sys.path) в самое начало добавляется текущая рабочая директория
>>> for path in sys.path:
... print(f'"{path}"')
""
"/usr/lib/python37.zip"
"/usr/lib/python3.7"
...
Первая строка пустая, что и означает текущую рабочую директорию.
🔸 Если вы запускаете интерпретатор передавая скрипт как аргумент, то история получается иная. На первом месте будет директория в которой располагается скрипт. А текущая рабочая директория игнорируется.
Пишем скрипт с таким содержанием:
# script.py
import sys
for path in sys.path:
print(f'"{path}"')
Запускаем
python3 /home/user/dev/script.py
Получаем
"/home/user/dev"
"/usr/lib/python37.zip"
"/usr/lib/python3.7"
...
🔸 Если вы запускаете скрипт по имени модуля то на первом месте будет домашняя директория текущего юзера
python3 -m script
"/home/user"
"/usr/lib/python37.zip"
"/usr/lib/python3.7"
...
Скрипт должен быть доступен для импорта
На что это влияет?
На видимость модулей для импорта. Если вы ждёте, что, запустив скрипт по пути, сможете импортировать модули из текущей рабочей директории, то вы ошибаетесь. Придётся добавлять путь os.getcwd() в sys.path самостоятельно или заранее объявлять переменную PYTHONPATH.
#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