正在使用slack 注册聊天机器人,需要连接slack API,给出了一个秘密令牌,不知道怎么将这个秘密令牌输出环境变量中,是写在python脚本文件中吗,可是我执行python解释器的时候总是报错,请问这是怎么回事?
可是我在python脚本中输入这句代码有错误,请问怎么样才能用python新建环境变量,这个环境变量有什么用呢?
走同样的路,发现不同的人生
That’s not the case. If you are under Linux, just execute this sentence in the terminal:
export SLACK_BOT_TOKEN="*******"
So you can use the following statement in python to get:
import os token = os.getenv("SLACK_BOT_TOKEN")
Or you can just put SLACK_BOT_TOKEN写到.bashrc inside.
SLACK_BOT_TOKEN
.bashrc
If you are using Windows, it is different. It seems to be executed under cmd:
set SLACK_BOT_TOKEN="*******"
In [57]: os.environ["testtest"]="test" In [58]: os.environ.get("testtest") Out[58]: 'test'
Only valid for the current session. Not permanently.
That’s not the case. If you are under Linux, just execute this sentence in the terminal:
So you can use the following statement in python to get:
Or you can just put
SLACK_BOT_TOKEN
写到.bashrc
inside.If you are using Windows, it is different. It seems to be executed under cmd:
Only valid for the current session. Not permanently.