Наверняка вы замечали, что в Python есть удобная функция для получения переменной окружения
os.getenv(NAME)
И её "сестра" для создания или изменения переменных окружения
os.putenv(NAME, VALUE)
Но почему-то putenv() не работает как должно. Энвайромент не обновляется!
os.putenv('MYVAR', '1')
print(os.getenv('MYVAR'))
... и ничего 😴
Почему так?
На самом деле энвайромент обновляется, но это значение не добавляется в словарь os.environ.
Откройте исходник функции os.getenv(). Это просто шорткат для os.environ.get()
В то время как putenv() это built-in С-функция.
Словарь os.environ (или точней класс из MutableMapping) создаётся из энвайромента в момент инициализации. Функция putenv() самостоятельно его не изменяет.
В тоже время, когда вы создаёте или изменяете ключ в os.environ, автоматически вызывается putenv() в методе __setitem__().
То есть, технически putenv() всё делает верно, но в os.environ это не отражается. Можно проверить так:
>>> os.putenv('MYVAR', '123')
>>> os.system('python -c "import os;print(os.getenv(\'MYVAR\'))"')
123
Я объявил переменную в текущем процессе и вызвал дочерний процесс, который её унаследовал и получил в составе os.environ.
Аналогично при удалении переменной вызывается еще одна built-in функция unsetenv(), удаляющая переменную из системы.
Итого
▫️ Удобней всего явно обновлять переменные через os.environ
▫️ Есть способ неявно создать/удалить переменную через putenv/unsetenv, что не повлияет на os.environ но изменит энвайромент и передаст изменения сабпроцессам. Но так лучше не делать!
▫️os.environ это просто обертка для built-in функций putenv() и unsetenv().
#basic
Rovinj, #Croatia🇭🇷
Rovinj interestingly combines rich traditions and modernity, provincial charm and resort status. This city is still a fishing port, so seafood here is the freshest and tastiest.
Sibenik, #Croatia
Sibenik is the only Croatian city and certainly one of several in the world that boasts of having two UNESCO monuments: St. James Cathedral and the fortress.
🇭🇷#Croatia: Croatia has reintroduced compulsory military service after nearly 20 years.
Hundreds of young Croatians have reported for duty, with the first 800 conscripts beginning their two-month basic training at three barracks across the country: Knin, Slunj, and Požega.
Under the new system, up to 4,000 young men will be called up each year for short-term training. Croatian General Kundid said the program will be “very dynamic and very interesting” for conscripts.
Training will include traditional military skills as well as modern capabilities such as basic drone operation, drone defence, and cyberwarfare techniques and countermeasures.
(via @balkanspectator & BBC)
🗺 CROATIA 🇭🇷
A beautiful morning in the town of Rovinj🤩
The historic center of Rovinj is located on a peninsula shaped like a drop. The cathedral is located in the center.
Rovinj interestingly combines rich traditions and modernity, provincial charm, and resort status. This town is still a fishing port, so the seafood here is the freshest and tastiest.
#Croatia
@voyage
🗺 Croatia 🇭🇷
A beautiful morning in the town of Rovinj🤩
The historic center of Rovinj is located on a peninsula shaped like a drop. The cathedral is located in the center.
Rovinj interestingly combines rich traditions and modernity, provincial charm, and resort status. This town is still a fishing port, so the seafood here is the freshest and tastiest.
#Croatia
@voyage
Branko Mataja — Traditional And Folk Songs Of Yugoslavia (Essar Records, 1974)
#guitar#Serbia#Croatia#Yugoslavia
Свой единственный альбом с гитарными интерпретациями народной музыки Югославии Бранко Матая записал у себя дома. Все композиции он исполнил самостоятельно на модифицированной им самим же гитаре. Поэтому «Традиционные и народные песни Югославии» звучат скорее не как урок истории народной музыки родины Матаи, а как интимное, личное общение между исполнителем и слушателем.
Коллекция гитарных медитаций Бранко Матая оставалась в безвестности, пока не была вновь открыта в начале 2000-х. В 2022 году альбом перевыпустил лейбл Numero Group.
🔗Spotify | AppleMusic | Bandcamp
🇰🇬🇭🇷 В рамках официального визита Министра иностранных и европейских дел Республики ХорватияГордана Грлич Радмана в Кыргызскую Республику 12 декабря 2024 года состоялись его переговоры в узком и расширенном составе с Министром иностранных дел Кыргызской РеспубликиЖээнбеком Кулубаевым.
▶️Толук маалымат/Подробнее: mfa.gov.kg
#МИДКР#ТИМ#Kyrgyz_MFA#Kyrgyzstan#Croatia
Friendlies🏳
2026-03-31 23:00 UTC
USA vs. Portugal
Predicted outcome: USA❌
Predicted score: 3:2
Actual: Portugal 0:2
#USA#Portugal
2026-03-31 23:30 UTC
Argentina vs. Zambia
Predicted outcome: Argentina✅
Predicted score: 2:0
Actual: Argentina 5:0
#Argentina#Zambia
2026-04-01 00:00 UTC
Brazil vs. Croatia
Predicted outcome: Brazil✅
Predicted score: 2:1
Actual: Brazil 3:1
#Brazil#Croatia
2026-04-01 01:00 UTC
Mexico vs. Belgium
Predicted outcome: Belgium❌
Predicted score: 1:3
Actual: Draw 1:1
#Mexico#Belgium
#Football#Friendlies