[英]How can I SET an OS key in windows to have access to it later in Python?
I'm trying to imitate export Key_value="My value"
from Linux on my Windows computer but in my terminal it doesn't work.我试图在我的 Windows 计算机上从 Linux 模仿
export Key_value="My value"
但在我的终端中它不起作用。 I saw that maybe I should use SET
instead export
but when I print my environment dictionary my key and value aren't there, only the normal OS values.我看到也许我应该使用
SET
而不是export
但是当我打印我的环境字典时,我的键和值不存在,只有正常的操作系统值。
The command in the cmd console is: cmd控制台中的命令是:
setx your_key_value "your value"
You can do it manually too if you go to "environmental variables" using windows menu and typing that, then go to environmental variables and add the one that you want to insert.如果您使用 Windows 菜单转到“环境变量”并输入该内容,然后转到环境变量并添加要插入的变量,则也可以手动执行此操作。
My problem then was that I set it but it was not reflected in the os.environment
dictionary.我的问题是我设置了它,但它没有反映在
os.environment
字典中。 I restarted my computer and tried again and there it was.我重新启动了我的电脑并再次尝试,它就在那里。 I think that OS variables are set only when you start your computer.
我认为只有在您启动计算机时才会设置操作系统变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.