Наверняка вы замечали, что в 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
Trump's $TRUMP coin surges 30% after exclusive dinner invite for top holders announced.
The event, hosted at his golf club, fuels trading frenzy and ethical debates.
#TrumpCoin#CryptoPolitics
🖼 Trending now: #CryptoPolitics - Major crypto firms back Trump’s White House fundraiser. #Regulation#USPolitics
🇺🇸 最新消息:Coinbase、Ripple、Tether 以及 Winklevoss 雙子星等多家加密企業,均為川普白宮宴會活動的主要捐助者之一。
此舉被視為加密產業加強與政治接軌的關鍵信號,或將影響未來監管與政策走向。 #Insight
@EthereumGlobalNews Follow for more global Web3 & DeFi updates!
Crypto Companies Sponsor Trump's Inauguration
🔵 The inauguration will take place on January 20 at 20:00 MSK. Sponsor list includes ONDO, SOL, SUI, Coinbase, MetaMask, Gemini, and Galaxy.
🔥 The crypto industry strengthens its political position.
🧑⚖️ In other news, the SEC has filed a lawsuit against Nova Labs, the company behind Helium Network, for offering unregistered investment products linked to its cryptocurrency mining devices and user data exchange program.
Links:Crypto Twitter, News
#Crypto#Trump#SEC#Helium#NovaLabs#Solana#Coinbase#MetaMask#Gemini#Galaxy#ONDO#SUI#Dogecoin#DigitalAssets#CryptoPolitics#Cryptocurrency#News#Inauguration#Investment#Market
🚀 Tether-Linked PAC Makes Initial Expenditure Ahead of 2026 U.S. Midterm Elections
A political action committee associated with Tether, Fellowship PAC, has made its first expenditure ahead of the 2026 U.S. Congressional midterm elections. According to Odaily, the PAC paid approximately $300,000 to Nxum Group, a company co-founded by Bo Hines, to provide advertising services for Republican candidates.
Bo Hines currently serves as the head of Tether's U.S. operations and previously worked as a digital asset policy advisor in U.S. President Donald Trump's administration. Jesse Spiro, the chairman of Fellowship PAC, is also affiliated with Tether US.
Public records indicate that Nxum Group was established by Bo Hines and his partners. This transaction coincides with the PAC's initial expenditure report submission to the U.S. Federal Election Commission (FEC). Although Fellowship PAC has announced plans to invest up to $100 million in support of crypto-friendly candidates, its current account disclosures show nearly zero funds.
Under U.S. campaign finance regulations, political committees can pay affiliated entities for services, provided they adhere to the "fair market price" principle. This has sparked discussions about potential conflicts of interest.
Fellowship PAC has begun targeted advertising and candidate support in Republican elections, positioning itself as a new political influence tool for the crypto industry in the 2026 election cycle. However, questions remain regarding the transparency of its funding sources and operations.
#Tether#FellowshipPAC#2026Midterms#USPolitics#CampaignFinance#CryptoPolitics#BoHines#RepublicanCandidates#PoliticalActionCommittee#ElectionAdvertising#CryptoInfluence#FEC#PoliticalFunding#ConflictOfInterest#NxumGroup