My Day1, myday1

Source: Internet
Author: User

My Day1, myday1

I. user input

When entering the password, if you want to be invisible, you need to use the getpass method in the getpass module, that is:
#! /Usr/bin/env python #-*-coding: UTF-8-*-import getpass # assign the user input content to the name variable pwd = getpass. getpass ("Enter Password:") # print the entered content print (pwd)
Ii. Modules

Python is powerful because it has a rich and powerful standard library and third-party library. Almost any function you want to implement has the corresponding Python library support, in future courses, we will explain in depth the various frequently-used libraries. Now, let's start with a symbolic study of two simple ones.

Sys

#! /Usr/bin/env python #-*-coding: UTF-8-*-import sys print (sys. argv) # output $ python test. py helo world ['test. py', 'HELO', 'World'] # obtain the parameters passed during script execution.

OS

#! /Usr/bin/env python #-*-coding: UTF-8-*-import OS. system ("df-h") # Call system commands

Fully integrated

Import OS, sys OS. system (''. join (sys. argv [1:]) # Use your input parameters as a command and submit it to OS. system for execution.

Write a module by yourself

Python tab completion Module

1 import sys2 import readline3 import rlcompleter4 5 if sys.platform == 'darwin' and sys.version_info[0] == 2:6     readline.parse_and_bind("bind ^I rl_complete")7 else:8     readline.parse_and_bind("tab: complete")  # linux and python3 on mac
For MAC
 1 #!/usr/bin/env python  2 # python startup file  3 import sys 4 import readline 5 import rlcompleter 6 import atexit 7 import os 8 # tab completion  9 readline.parse_and_bind('tab: complete')10 # history file 11 histfile = os.path.join(os.environ['HOME'], '.pythonhistory')12 try:13     readline.read_history_file(histfile)14 except IOError:15     pass16 atexit.register(readline.write_history_file, histfile)17 del os, histfile, readline, rlcompleter
For Linux

You can use it after saving it.

localhost:~ jieli$ pythonPython 2.7.10 (default, Oct 23 2015, 18:05:06)[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import tab
  • You will find that the tab. py module you wrote above can only be imported in the current directory. What if you want to use it in any part of the system? Now you need to put this tab. py is stored in the python global environment variable Directory, which is generally stored in a directory named Python/2.7/site-packages. The directory is placed in different operating systems in different locations, print (sys. path) to view the python Environment Variable list.

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.