Наверняка вы замечали, что в 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
https://docs.python.org/3/library/marshal.html#module-marshal
marshal — Internal Python #object_serialization
This module contains functions that can read and write Python values in a binary format. The format is specific to Python, but independent of machine architecture issues (e.g., you can write a #Python value to a #file on a PC, transport the file to a Sun, and read it back there). Details of the format are undocumented on purpose; it may change between Python versions (although it rarely does).
@thefavbot
Qué puede hacer este bot?
Este bot puede recopilar todos sus medios en un solo lugar.
Usted puede acceder a sus medios favoritos en cualquier chat!
Para eso debes escribir @thefavbot en el chat que deseas. Soporta:
Foto, video, archivo, audio, voz, gif.
Para agregar cualquier medio a su colección, solo necesita enviarlo o reenviarlo al bot.
Idioma: Inglés
(visto en @BotsGram_cu)
#gift, #video, #image, #file
#Musicopy#Music#File#Transfer
Join the Musicopy: Music File Transfer beta on ✈️#TestFlight
🔗 Link: https://testflight.apple.com/join/Ck9KaZVR
Shared by Dimitri
Sharing
Share files and apps on android to other devices using browser
Share files and apps over HTTP.
You need the other device to be connected to the same network. just toggle on the server and scan the QR Code on other device and you're good to go. Files sent from browser to the app can be found in Sharing/ folder in your internal storage. You can always disable uploads in the app settings.
https://github.com/Ammar64/Sharing
Download
https://github.com/Ammar64/Sharing/releases/latest
https://f-droid.org/packages/com.ammar.sharing/
#share#file#Transfer#Android#qr
@warlockpublicurl_bot
Qué puede hacer este bot?
Envíale cualquier Archivo Multimedia de Telegram y generará un enlace directo para ello
Los Archivos Porno están Estrictamente Prohibidos.
Idioma: Inglés
(visto en @BotsGram_cu)
#file, #upload, #link, #url, #public, #telegram