简体   繁体   English

如何检查 python-dotenv 是否创建了环境变量?

[英]How to check wether a python-dotenv creates the environmet variable?

I am novice in IT.我是 IT 新手。 Sorry for possible stupid question.抱歉可能是愚蠢的问题。
I want to check wether python-dotenv really creates environment variable.我想检查 python-dotenv 是否真的创建了环境变量。
So I add.env file with my MYVAR.所以我用我的 MYVAR 添加了 env 文件。
Then I execute python file within code:然后我在代码中执行 python 文件:
import dotenv; dotenv.load_dotenv(); import os; os.environ['MYVAR']
and get correct value.并获得正确的价值。
But if I further check echo $MYVAR in Terminal - where is no such variable.但是,如果我进一步检查终端中的echo $MYVAR - 哪里没有这样的变量。
Is the python-dotenv really creates the env.v. python-dotenv 是否真的创建了 env.v。 or just implement its own way to parse pairs key-value?或者只是实现自己的方式来解析键值对?

Here's what I understand from the docu :这是我从文档中了解到的内容:

If your application takes its configuration from environment variables, like a 12-factor application, launching it in development is not very practical because you have to set those environment variables yourself.如果您的应用程序从环境变量中获取其配置,例如 12 因子应用程序,那么在开发中启动它并不是很实际,因为您必须自己设置这些环境变量。

To help you with that, you can add Python-dotenv to your application to make it load the configuration from a.env file when it is present (eg in development) while remaining configurable via the environment:为了帮助您解决这个问题,您可以将 Python-dotenv 添加到您的应用程序中,以使其在存在时(例如在开发中)从 a.env 文件加载配置,同时保持可通过环境进行配置:

So dotenv will set environment variables only for the process in which it runs.所以 dotenv 只会为它运行的进程设置环境变量。 The idea is to support development of applications that use environment variables.这个想法是为了支持使用环境变量的应用程序的开发 See also https://12factor.net/config .另请参阅https://12factor.net/config

It is not the use case for dotenv to permanently set environment variables.永久设置环境变量不是dotenv 的用例。 You would rather do that with specific tools of your operating system.您宁愿使用操作系统的特定工具来做到这一点。

Your test confirms that setting environment variables for an application works.您的测试确认为应用程序设置环境变量有效。 But the values are not set permanently.但是这些值不是永久设置的。 They are not visible outside the application or after it ends (and not intended to be).它们在应用程序外部或结束后不可见(并且不打算如此)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM