Handling of sensitive information (user name, password, etc.) in Python--add to environment variables

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.