Наверняка вы замечали, что в 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
🎉 It Finally Happened: SEC Approves SPOT BTC-ETFs! 🚀
💡What This Means: SPOT BTC-ETFs let investors get into Bitcoin through more traditional investment avenues. This brings in more investors and makes the crypto market more like the traditional financial market.
🤝Join SLEX Exchange, catch the bull run wave, and trade Bitcoin to boost your earnings on the spot market!
#CryptoNews#SECBTCETF#Bitcoin#CryptoAdoption#FinancialMileston
Website| Telegram | Reddit | Facebook | Instagram | Medium | Linkedin | Twitter
🚀 Polygon Stablecoin Supply Hits Record High of $3.6 Billion
The stablecoin supply on the Polygon network has reached a new peak, totaling $3.6 billion. According to NS3.AI, this milestone was confirmed by data from Artemis, indicating that the network has achieved an all-time high in stablecoin holdings. This development highlights the growing adoption and utilization of stablecoins within the Polygon ecosystem.
#Polygon#Stablecoin#Crypto#Blockchain#DeFi#Cryptocurrency#DigitalAssets#CryptoAdoption#CryptoNews#FinTech#POL
Bitcoin Rise and Market Liquidations
Bitcoin reaches $94,000, indicating market volatility. In 24 hours, $655 million liquidated from crypto assets. USDt-TON sees accelerated growth: over 1 billion issued and integrated with major exchanges. Telegram adoption boosts usage, making crypto accessible to 950 million users. Read more on market events and USDt-TON's progress through Watcher Guru and other sources.
#Bitcoin#Crypto#USDC#USDt-TON #TON#Telegram#WhaleAlert#MarketTrends#Liquidation#Blockchain#Stablecoin#Investing#Altcoins#VentureCapital#FinTech#Web3#DataAnalysis#CryptoAdoption
U.S. Must Lead in Crypto Regulation
U.S. Treasury Secretary Bessent emphasizes the need for the U.S. to take a global lead on cryptocurrency. Key points include bringing Bitcoin transactions onshore and ceasing government Bitcoin sales. Notably, the evolving regulatory landscape also aims to foster greater adoption of cryptocurrencies in the U.S.
#Crypto#U.S. #Bitcoin#Regulation#SEC#BTC#Blockchain#Innovation#CryptoAdoption#Finance#Bessent#Investment#CryptoPolicy#DigitalAssets#Mainstream#MarketTrends#Tech
Uniswap Expands Crypto-to-Fiat Options
Uniswap collaborates with Robinhood, MoonPay, and Transak to enable seamless crypto-to-fiat transactions. Users across 180+ countries can convert crypto and deposit funds directly into bank accounts via the mobile wallet. This feature will soon be available on the browser extension and web version. For more details, visit Leviathan News.
#Uniswap#Crypto#Robinhood#MoonPay#Transak#Banking#Fiat#DEX#Blockchain#Finance#Tech#Global#Innovation#Payments#Wallet#Transactions#Defi#Onboarding#CryptoAdoption#VC
🚀 Bitcoin Bancorp Expands Bitcoin ATM Network in Southern California
Bitcoin Bancorp has announced the launch of a licensed Bitcoin ATM network in Southern California, with the first machines now operational in the Los Angeles area. According to Odaily, this marks a new phase in the company's retail expansion in the United States, following its previous deployment in Texas, highlighting its strategy to accelerate growth in key markets.
Data indicates that the United States currently hosts over 35,000 Bitcoin ATMs, with the industry expected to grow from approximately $267 million in 2025 to $7.68 billion by 2034. California, with its large population, advanced tech ecosystem, and high rate of cryptocurrency adoption, is a significant growth market, ranking among the top states in the nation for ATM installations, second only to states like Texas.
#BitcoinBancorp#BitcoinATM#SouthernCalifornia#LosAngeles#RetailExpansion#Cryptocurrency#BitcoinMarket#CaliforniaTech#CryptoAdoption#USBitcoinATMs#ATMInstallations#BitcoinGrowth#BTC