Python modules for beginners

Python has a very rich and powerful standard library and third-party libraries

 

Common storage paths for the Python standard library:

'D:\\python\\untitled1\\venv\\lib

Common storage paths for Python third-party libraries:

'D:\\python\\untitled1\\venv\\lib\\site-packages'

 

Today I simply learned two standard libraries sys and os

1  # Author:Alex Li 
2  
3  import sys
 4  
5  print (sys.path) #environment variable 6 
print  ( sys.argv) #script relative path,[2]

 

1  # Author:Alex Li 
2  
3  import os
 4  
5 cmd_res = os.system( " dir " ) #Execute the command without saving the result, the output is 0 
6 cmd_res = os.popen( " dir " ) #Output memory address 
7 cmd_res = os.popen( " dir " ).read() #Output command result 
8  
9  print ( " ------ " ,cmd_res) #The output is 0, which means the execution is successful 
10  
11 os.mkdir( " new_dir ") #create directory

 

You can also write modules yourself, I wrote a user input module

 

 1 # Author:Alex Li
 2 import getpass
 3 
 4 _username = "alex"
 5 _password = "abc123"
 6 
 7 username=input("username:")
 8 password=input("password:")
 9 #password=getpass.getpass("password:") jia mi
10 
11 if _username==username and _password==password:
12     print("wlecome user {name} login...".format(name=username))
13 else:
14     print("invalid username or password!")

and then call

 1 # Author:Alex Li 2 import login #By default , search from the current directory to the environment variable directory, so just put it in the environment variable directory 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325209198&siteId=291194637