environ对C扩展模块的可见性

environ对C扩展模块的可见性

本文介绍了os.environ对C扩展模块的可见性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我使用 os.environ 更改环境变量,那么以后导入的模块会看到这个变化吗?



具体来说, sqlite3 说:

所以如果SQLite库在更改 os.environ

If I change environment variable using os.environ, do the modules I import afterwards see that change?

Specifically, sqlite3 requires the use of an environment variable to determine its temporary file location. But if I use os.environ['SQLITE_TMPDIR'] = '.' before import sqlite3, it does not have the desired effect. Why?

解决方案

The sqlite3 module is just a wrapper for the SQLite C library, so it will not directly see any changes made to os.environ.

However, the documentation says:

So if the SQLite library is initialized after you've changed os.environ, it will see the changes.

Please note that SQLite reads different environment variables on Unix-y OSes and on Windows.

这篇关于os.environ对C扩展模块的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 14:31