Наверняка вы замечали, что в 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
🔤🔤🔤🔤🔤
StepMania is officially live! 🥂
More steps – more coins, guys!
StepMania is not just a pedometer but a move-to-earn app where every step is rewarded, new records keep you motivated, and the community fuels the excitement.
How does StepMania work?
🌎Pedometer – track your activity and set personal records!
🥇Leaderboards – compete with friends and other users to reach the top!
💬Community – share your achievements, exchange tips, and stay motivated!
🏳️Plus, awesome giveaways! Gadgets, subscriptions, and other bonuses for active users right from the start!
Stop tapping! With StepMania, walking is not just healthy but also rewarding. Step up and earn.
Walk to Earn
Join the game👉link
#Stepn#Stepmania#Earn
Crypto Currents | Get referrals | Buy Telegram Stars
❤️Vanilla Finance Closes Pre-Seed Investment Round ✔️
Singapore, November 26, 2024 – Vanilla Finance, the leading exchange by trading volume on #Telegram, has announced the successful closure of its Pre-Seed investment round. Spearheaded by industry giants like Paper Ventures, UOB Ventures, and ABCDE Labs, the round also attracted notable participants such as #HTX Ventures, #Ocular, #Openspace, #Y2 Ventures, and angel investors from #STEPN, #Scroll, #XAI, and more.
🔫A Game-Changer in the Digital Asset Space
Since its launch, #VanillaFinance has made waves, amassing over $8 billion in USDT trading volume within just 60 days. This meteoric rise is further validated by winning the prestigious #Binance MVB Season 8, a recognition of the platform’s cutting-edge solutions and market leadership.
👏Visionary Growth and User-Centric Innovation
With fresh funding and institutional backing, Vanilla Finance is on a mission to redefine crypto trading by:
• Simplifying User Experience: Introducing intuitive, secure features tailored for both novices and experts.
• Expanding Offerings: Launching a spot market, with a focus on meme trading pairs, and rolling out features like a meme creator platform, staking products, and futures trading.
• Regional Focus: Targeting Southeast Asia and APAC with localized services, multilingual support, and integration with regional payment systems.
💰Institutional Confidence in a Bright Future
The involvement of strategic investors highlights Vanilla Finance’s potential. A UOB Ventures spokesperson praised the platform’s innovative approach, while Danish Chaudhry of Paper Ventures noted, “Vanilla Finance’s expansion aligns perfectly with the Southeast Asia and APAC markets’ untapped opportunities in digital finance.”
📖Building a Next-Generation Ecosystem
Beyond trading, Vanilla Finance is creating an ecosystem that prioritizes community engagement and innovation. With its unique approach to meme trading and user-focused features, the platform is poised to set a new benchmark in digital asset trading.
✈️The Future Starts Here: Vanilla Finance is committed to serving the next 100 million users, shaping a more inclusive, engaging, and forward-thinking crypto landscape.
❤️ Join Vanilla mini-app now and get as much $CONE as you can before the airdrop!