TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #303 · 27 дек.

Наверняка вы замечали, что в 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

Hashtags

Резултати

Пронајдени 2 слични објави

Пребарај: #exhibitions

当前筛选 #exhibitions清除筛选
Bali News

@balinews · Post #113 · 10.07.2024 г., 12:05

🤖A unique art exhibition Neuro Conflict will take place in Bali 📍 This weekend from 12 to 14 July, Superlative Gallery in Kuta will host an unusual exhibition called Neuro Conflict. Here you can experience a unique combination of art and modern technology, including neural networks. 🤖 The event will run for three days. The exhibition will feature works by international artists, interactive art installations, fascinating lectures on artificial intelligence, as well as performances and an auction. @BaliNews #wheretogo#exhibitions#Kuta

Bali News

@balinews · Post #304 · 28.01.2025 г., 05:30

🧉Bali will host the official Arak Day tomorrow 🏝 Arak Day, the local palm vodka, is celebrated tomorrow, January 29. ℹ️ Arak is a symbol of offering to the gods for a rich harvest, a form of gratitude. 📍 The official event will be held at GWK Park. The “Arak Berem Bali for the World” exhibition will also be held there. 🐲 The organizers of the celebration emphasize that Arak Day in Bali is not about drinking at all. Arak Day celebrations should be understood as a temple festival that is celebrated through prayer, not alcoholism. @BaliNews #holidays#events#exhibitions#culture