Первая директория в 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
🔖 How Ukraine’s killer drones are beating Russian jamming | Hacker News #pinboard#warfare
As an engineer, I am fascinated by it all. As a human, I am horrified that we democratized violence on this scale.
A missile worth perhaps a million dollars can kill maybe 12 or 20 people. But for one million dollars, you can buy 10,000 drones, put four grenades on each, and they will kill 1,000 or even 2,000 people or destroy 200 tanks.
https://news.ycombinator.com/item?id=44168658
🚨🇺🇸TRUMP: IRANIAN OPERATIONS WILL END "VERY SOON" BUT NOT THIS WEEK
🔹 11 days of military action have dismantled Iran's radar, telecommunications, leadership, missile stockpiles, and navy 💥
🔹 US forces destroyed 10 Iranian mine-laying vessels in Strait of Hormuz yesterday — key route for 20% of global oil 🛢️
🔹 Defense Secretary Hegseth calls March 10 "most intense" day of bombardment — 140 US troops wounded, 7 killed ⚰️
🔹 President warns "death, fire, and fury" if Tehran disrupts shipping lanes — tensions escalating 🔥
The Commander-in-Chief knows exactly what he's doing 😤💪
#USNews#MiddleEast#warfare
@america
🌎 Ancient Greek fire, known as "Greek fire," was a weapon that could burn even on water. This flammable liquid, projected from tubes, terrified enemies at sea and kept its formula a closely guarded secret, lost to history. ✨
#history⚡#chemistry⚡#warfare
👉subscribe Interesting Planet
📢 Ukraine's defense forces resort to using Leopard tanks as long-range artillery, failing to fulfill their intended purpose against Russia. The highly anticipated offensive has turned into a defensive strategy, with the giant tanks deployed along the front line. But will this change the course of the conflict? Meanwhile, Poland plans to provide Ukraine with additional armored firepower. The war continues... 💥#Ukraine#Russia#LeopardTanks#Warfare
https://www.gazeta.ru/army/news/2023/12/05/21855127.shtml
Subscribe to @BadVolfNews