如何用python脚本以环境变量输出秘密令牌?
怪我咯
怪我咯 2017-04-18 09:44:38
0
2
398

正在使用slack 注册聊天机器人,需要连接slack API,给出了一个秘密令牌,不知道怎么将这个秘密令牌输出环境变量中,是写在python脚本文件中吗,可是我执行python解释器的时候总是报错,请问这是怎么回事?

可是我在python脚本中输入这句代码有错误,请问怎么样才能用python新建环境变量,这个环境变量有什么用呢?

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(2)
黄舟

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.

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!