Наверняка вы замечали, что в 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
🚀 To celebrate the partnership with @AEON_Commuinty, the leading crypto payment framework, built for AI to drive intelligent, automated payments across Web3 and simplify how crypto works in real life, we're hosting a GIVEAWAY! 🎉Total $700 Up For Grabs!
⏰May 1st, 10:00 AM - May 20th, 10:00 AM (UTC)
1️⃣$200 raffle for qualified #Galxe participants
2️⃣$500 rewards via AEON Pay for TOP and FCFS consumers
Consume $UXLINK to cover daily expenses (Each transaction must over $5).
👀Stay tuned for the upcoming announcement! In the meantime, feel free to take a sneak peek here 👉https://t.me/aeon_pay_bot
The competition is heating up, and it's time to take your skills to the next level in our #TON Capital #Galxe Campaign!⚡️
With more tasks, bigger rewards, and an even tougher playing field, the challenge is yours to conquer.
💪 Complete missions, accumulate points, and rise to the top of the leaderboards for your chance to claim extraordinary rewards. From challenges and quizzes to community actions, every task pushes you closer to victory.
🎁 The Best Will Be Rewarded:
🏆A $1000 USDT prize pool awaits the Lucky 100 on our Galxe campaign leaderboard
🏅Exclusive badges for the Lucky 500 contributors ( Galxe Explorer + Guaranteed Whitelist)
🎯Access to the Season 1 Expedition Grand Prize, worth up to $50,000 and 88.8m $TONCAP!
Join TON Capital Galxe Campaign -- https://app.galxe.com/quest/SAw9YJRiY3VF2oevPJpa3K/GCWPWtKwCQ
Show us what you’ve got and seize your opportunity to be part of something great in the world of TON and Web3.
⚡️The future is yours to shape!
🎉 Solana Leveling #Airdrop on #Galxe🎉
We’re giving away $5 to 10 lucky winners 💸
✅ Complete simple social tasks
✅ Join the Solana Leveling community
✅ Stay updated with the best Solana insights
👉 Enter here:https://app.galxe.com/quest/AygxpG3nDj4VfTNkmsTrpN/GCUxJt6zNX
🆕 Galxe now fully supports #TokenPocket login!
👉https://extension.tokenpocket.pro/
Galxe is the leading platform for building the Web3 community.
🔥Follow TokenPocket Space and Get Ready for the #TokenPocketChristmas on #Galxe!
👉https://galxe.com/TokenPocket
Details:
👉https://twitter.com/Galxe/status/1729918366012600584
👉https://twitter.com/TokenPocket_TP/status/1730068829311774726
⚡️Electra launches a quest on Galxe!
We are pleased to announce that🚀Electra launches an exciting $ELT token reward campaign on the #Galxe platform!
This means that Airdrop is just around the corner!
🏆
💵 As part of this campaign, you have the opportunity not only to earn $ELT tokens, but also to participate in prize draws in $USDT, unique NFTs and tokens from top partners🤝Electra!
Complete quests, follow the news and get ready for the $ELT airdrop!
➡️Take part in the campaign
#Electra#Airdrop#DeFi#Web3
Become an APTOS and SUI supporter and reach new peaks⛰
Go to Galxe 👇
https://galxe.com/apstation/campaign/GCLYeU42e1…
#Aptos#Galxe#AptosEcosystem#Sui#SuiEcosystem
https://twitter.com/CetusProtocol/status/1621413895578726400?s=20&t=idtvF7UcG6zXWiw2NhUUdA
@everyone
🔥Airdrop – Empeiria x Leap Wallet ✅
💠Reward:Empe Micro Node (worth $50) – Grants access to EMPE token staking rewards. Claiming starts after TGE.
☀️Airdrop Link :- Click Here
⚙️How to Participate?
♦️Jointheevent on Galxe
♦️Complete all listed quests
♦️Connect your wallet & verify tasks
♦️Secure yourEmpe Micro Node reward
📌Note:Limited-time event – don’t miss your chance to get early staking access with Empeiria
®Note - Please do your own research (DYOR) before joining to any airdrops project, also airdrop is 100% free. Don't send any fee or penny for receiving airdrop tokens.
#Empeiria#LeapWallet#Galxe#Airdropcomic#CryptoRewards#Web3