Objective:
When writing a Python program, you often encounter such as: Send mail, configure account information. It is unavoidable to fill in the sensitive information in the Python program, this time can write the sensitive information to the system environment variable, through Python comes with the OS module to get the variable.
Under Linux:
[Email protected]:~# export username=cctv[email protected]:~#[email protected]:~# pythonpython 2.7.3 (default, Mar 14 201 4, 11:57:14) [GCC 4.7.2] on Linux2type ' help ', ' copyright ', ' credits ' or ' license ' for more information.>>> import os>>> USERNAME = os.environ.get (' USERNAME ') >>> USERNAME ' CCTV '
Under Windows:
(ENV) F:\pythonclass>set USERNAME=CCTV (env) F:\pythonclass>pythonpython 2.7.10 (default, May, 09:44:00) [MSC V.1500 (AMD64)] on Win32type ' help ', ' copyright ', ' credits ' or ' license ' for more information.>>> import o s>>> use = Os.environ.get (' USERNAME ') >>> use ' CCTV '
As above, use the Os.environ.get (' variable name required ') method to get the value of the variable you want. This way you can write a program without worrying about the disclosure of sensitive information.
This article is from the "Cat Demon Blog" blog, please be sure to keep this source http://maoyao.blog.51cto.com/8253780/1775650
Handling of sensitive information (user name, password, etc.) in Python--add to environment variables