在python中取消设置Linux环境变量的正确方法是什么? [英] What is the correct way to unset a linux environment variable in python?

查看:332
本文介绍了在python中取消设置Linux环境变量的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从文档中:

如果平台支持unsetenv()功能,则可以删除此映射中的项目以取消设置环境变量.从os.environ中删除项目时,以及调用pop()clear()方法之一时,将自动调用unsetenv().

If the platform supports the unsetenv() function, you can delete items in this mapping to unset environment variables. unsetenv() will be called automatically when an item is deleted from os.environ, and when one of the pop() or clear() methods is called.

但是,无论unsetenv()是否可用,我都希望它能够工作.如果不可用,如何从映射中删除项目? os.environ['MYVAR'] = None?

However I want something that will work regardless of the availability of unsetenv(). How do I delete items from the mapping if it's not available? os.environ['MYVAR'] = None?

推荐答案

只是

del os.environ['MYVAR']

应该工作.

这篇关于在python中取消设置Linux环境变量的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆