问题描述
如果我使用 os.environ
更改环境变量,那么以后导入的模块会看到这个变化吗?
具体来说, sqlite3
说:
所以如果SQLite库在更改 os.environ $ c $请注意,SQLite读取不同的环境变量和。
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扩展模块的可见性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!