1. ํ๊ฒฝ๋ณ์ ์ ์ฅํ๊ธฐ
- Terminal ์ฐฝ์์ export command๋ฅผ ์ด์ฉํ์ฌ ํ๊ฒฝ๋ณ์๋ฅผ ์ ์ฅํฉ๋๋ค.
$ export ๋ณ์๋ช =๊ฐ
- ํ๊ฒฝ๋ณ์ ์ญ์ ๋ unset command๋ฅผ ์ด์ฉํฉ๋๋ค.
$ unset ๋ณ์๋ช
2. Python์์ ๋ถ๋ฌ์ค๊ธฐ
- os.environ๋ os.getenv ๋ฅผ ์ด์ฉํ์ฌ ํ๊ฒฝ๋ณ์๋ฅผ ๊ฐ์ ธ์ฌ ์ ์์ต๋๋ค.
environ์ ํด๋น ๋ณ์๊ฐ ์์ ๊ฒฝ์ฐ ERROR ๋ฅผ ๋ฐ์์ํค๊ธฐ ๋๋ฌธ์ getenv ๋ฅผ ์ฌ์ฉํ์๋ ๊ฒ์ ์ถ์ฒํฉ๋๋ค.
getenv๋ ํด๋น ๋ณ์๊ฐ ์์ ๊ฒฝ์ฐ NONE ์ returnํฉ๋๋ค.
import os
print('\ngetting_system_value.py {}\n'.format('-'*20))
# ==================================
# fine special value
# - os.environ['value_name'] return string
# - return "Error" if don't have value
# - you should write "try - catch"
# ==================================
s = os.environ['XDG_RUNTIME_DIR']
print('\t1. An environment value >> {}\n'.format(s))
# ==================================
# fine special value
# - os.getenv('value_name') return string
# - return None if don't have value
# ==================================
s = os.getenv('user_id')
print('\t2. An environment value >> {}\n'.format(s))
# ==================================================
# fine all value
# - os.environ.keys() return <class 'collections.abc.KeysView'>
# - If you want sort them, you have to cast list from class
# ==================================================
ls = list(os.environ.keys())
ls.sort()
print('\t3. All environment value')
for item in ls:
print('\t\t{}={}'.format(item, os.environ[item]))
'Lang > ๐ Python' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
๐ Python * Message ์ํธํ AES128, HMAC (0) | 2020.03.09 |
---|---|
๐ Python * MySQLdb ๋ชจ๋ ์ค์น (0) | 2020.03.09 |
๐ Python * socket ์ฐ๊ฒฐ + ๋ฌธ์์ด ์ ์ก (0) | 2020.03.09 |
๐ Python * MQTT module paho๋ฅผ ์ด์ฉํ MQTT ํต์ (0) | 2020.03.09 |
๐ Python * ๋ฌธ์ โ ์์คํค์ฝ๋ ๋ณํํ๊ธฐ (0) | 2020.03.09 |