Первая директория в 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
😄Paint
➖➖➖➖➖➖
🔘 The noun paint refers to coloured liquid that makes things look nice. The verb has different meanings. It can mean to put paint on something with a brush.
🔜 I'm going to paint this wall yellow, and this one white.
🔜The table was painted green.
🔘 Paint can also mean to make a picture of something, using paint.
🔜 She painted a portrait of me, it looks great.
🔜 The artist painted the beautiful landscape.
🔘 Paint can also mean to apply a liquid (not just paint) to something with a brush.
🔜 Paint the pastry with egg before putting it in the oven.
🔜 Paint the wood preserver on the fence to protect it.
#Paint👨🏫@America
➖➖➖➖➖➖➖➖➖➖➖➖
🆕 Crypto News @Money
😁 Crypto Game @Egame
🇺🇸 US News @America
🇯🇵 Japan News @Japan
🇦🇪 UAE News @Dubai
▶️ Popular Movies @Videos
😜 Best Funny Video @Funnys
😄Paint
➖➖➖➖➖➖
🔘 The noun paint refers to coloured liquid that makes things look nice. The verb has different meanings. It can mean to put paint on something with a brush.
🔜 I'm going to paint this wall yellow, and this one white.
🔜The table was painted green.
🔘 Paint can also mean to make a picture of something, using paint.
🔜 She painted a portrait of me, it looks great.
🔜 The artist painted the beautiful landscape.
🔘 Paint can also mean to apply a liquid (not just paint) to something with a brush.
🔜 Paint the pastry with egg before putting it in the oven.
🔜 Paint the wood preserver on the fence to protect it.
#Paint👨🏫@America
➖➖➖➖➖➖➖➖➖➖➖➖
🆕 Crypto News @Money
😁 Crypto Game @Egame
🇺🇸 US News @America
🇯🇵 Japan News @Japan
🇦🇪 UAE News @Dubai
▶️ Popular Movies @Videos
😜 Best Funny Video @Funnys