Article From:https://www.cnblogs.com/neilyoung22/p/9215722.html
 1 import time
 2 #The time to get CPU:
 3 #Get local time:
 4 #Get the standard time format:
 5 #Get the timestamp:
 6 #print(time.clock())             #This is about to be abandoned at 3
 7 print(time.process_time())       #This has no effect on the Mac platform
 8 print(time.localtime())          #The structured time time.struct_time (tm_year=2018, tm_mon=6, tm_mday=22, tm_hour=13, tm_min=36, tm_sec=13, TM) is obtained._wday=4, tm_yday=173, tm_isdst=0)
 9 print(time.asctime())           #Fri Jun 22 13:38:28 2018
10 print(time.ctime())             #Fri Jun 22 13:39:01 2018
11 print(time.time())              #1529646045.177513  1970The time stamp to the present
12 
13 # Transformation of time format:
14 
15 #String conversion to structured time
16 #Time stamp is converted to structured time
17 #Transform the structure time into a timestamp
18 #Transform structured time into strings
19 print(time.strptime("2018/06/22","%Y/%m/%d"))
20 print(time.gmtime(time.time()))
21 print(time.mktime(time.localtime()))
22 print(time.strftime("%Y/%m/%d %H:%M:%S",time.localtime()))
 1 import datetime,time
 2 # Get the current standard time
 3 # Transform the timestamp into a date format
 4 # Add and subtract the current time plus 3 days minus 3 days plus 3 hours reduce 3 hours plus 30 minutes, reduce 30 points.
 5 # The replacement value of the time is singular
 6 print(datetime.datetime.now())
 7 print(datetime.date.fromtimestamp(time.time()))
 8 print(datetime.datetime.now() + datetime.timedelta(3))
 9 print(datetime.datetime.now() + datetime.timedelta(-3))
10 print(datetime.datetime.now() + datetime.timedelta(hours=3))
11 print(datetime.datetime.now() + datetime.timedelta(minutes=3))
12 a = datetime.datetime.now()
13 print(a.replace(hour=3,minute=30))  #Singular value
 1 # Random number module
 2 
 3 # Default random number 0 - 1
 4 # The integer range of random parentheses 2 sides are included
 5 # Floating-point range random
 6 # The specified random number range does not include the boundary value on the left
 7 # Random returns list of sequences
 8 print(random.random())
 9 print(random.randint(1,3))
10 print(random.uniform(1.1,5.6))
11 print(random.randrange(1,3))
12 print(random.choices('123sdasd123'))
1 import random
2 
3 # Application: verification code generation
4 code = ''
5 for i in range(5):
6     a = random.choice([random.randrange(0,9),chr(random.randrange(65,91))])  #Here is a list of 2 values in the list.7     code += str(a)
8 print(code)
 1 # OS Modular
 2 import os
 3 #lookup
 4 #Get the current directory;
 5 #Get the parent directory;
 6 #Get the current working directory path
 7 #Get all the files and subdirectories under the specified directory
 8 #Get the file directory information
 9 #Output operating system specific operator / / \
10 #Output line stop symbol win \t\n \n for current platform
11 #A string that outputs the path to the file
12 #The output string indicates the current use of platform win->'nt'; Linux->'posix'
13 #Get the system environment variable
14 #Return to the normalization path
15 #Divide the path into a two element array of files and directories
16 #The directory that gets the path returns to the directory of the path. In fact, it's the first element of os.path.split (path)
17 #Return the final file name of path.
18 #Determine whether the path exists
19 #Determine whether the path is an absolute path
20 #Determine whether there is a file under the path
21 #Determine whether there is a directory under the path
22 #Parameters that will be combined before multiple paths are combined with the first absolute path will be ignored.
23 #After returning multiple paths, the parameters before the first absolute path will be ignored.
24 #Gets the access time of files or directories under the path.
25 #Gets the modification time of files or directories under the path.
26 print(os.curdir)
27 print(os.pardir)
28 print(os.getcwd())
29 print(os.listdir())
30 print(os.stat())
31 print(os.sep)
32 print(os.linesep)
33 print(os.pathsep)
34 print(os.name)
35 print(os.environ)
36 print(os.path.abspath())
37 print(os.path.split())
38 print(os.path.dirname())
39 print(os.path.basename())
40 print(os.path.exists())
41 print(os.path.isabs())
42 print(os.path.isfile())
43 print(os.path.isdir())
44 print(os.path.join())
45 print(os.path.getatime())
46 
47 
48 #Create an increase
49 # Create a directory, which can be recursively
50 # Create a single directory
51 os.makedirs('dirname1/dirname2')
52 os.mkdir("abc")
53 
54 #delete
55 #Delete directory
56 #Delete single level empty directory, not empty to report the wrong
57 #Delete a file
58 os.removedirs("dirname1/dirname2")
59 os.rmdir('test')
60 os.remove("file")
61 
62 # modify
63 # Changing the current scripting working directory is equivalent to CD
64 # Rename a file or a directory
65 os.chdir("dirname")
66 os.rename("oldname","newname")
67 
68 # shellThe interaction of commands
69 # Run the shell command
70 os.system()
 1 import sys
 2 # The command line parameter List, the first element is the program itself path.
 3 # Exit program, exit (0) when normal exit
 4 # Getting the version information of the Python interpreter
 5 # Maximum Int value
 6 # Return the path of the module
 7 # sys.platform
 8 # Standardized output of the console
 9 print(sys.argv) #['E:/3-Exercise library /test/day18/test5.py']
10 print(sys.version) #Getting the version information of the Python interpreter
11 print(sys.maxint)
12 print(sys.path)
13 print(sys.platform)
14 sys.stdout.write('please:')
15 val = sys.stdin.readline()[:-1]
 1 import shutil
 2 #shutil Modular
 3 #Advanced file, folder, compression package processing module
 4 
 5 #Copying part of the file to another file can be part of the content.
 6 #Copy file
 7 #Only copy permissions. Content, group, and user are invariable
 8 #Copy status information, including: mode bits, atime, mtime, flags
 9 #Copy files and permissions
10 #Copy files and state information
11 #Recursively copy files, such as copytree (source, destination, ignore=ignore_patterns ('*.pyc','tmp*')).
12 #Recursively deleting files
13 #Recursive de - moving files
14 '''
15 Create a compressed package and return to the file path, such as zip, tar16 base_name: The file name of the compressed package can also be the path of the compressed package. When a file name is saved, it is saved to the current directory, otherwise it will be saved to the specified path.17 Such as: www => save to the current path18 Such as: /Users/wupeiqi/www => save to /Users/wupeiqi/19 format:    The types of compressed packets are "zip", "tar", "bztar" and "gztar".20 root_dir:    The folder path to be compressed (the default current directory)21 owner:    User, default current user22 group:    Group, default current group23 logger:    Used to log logs, usually logging.Logger objects24 '''
25 #shutil The processing of compressed packets is called two modules, ZipFile and TarFile.
26 shutil.copyfileobj(fsrc, fdst[, length])
27 shutil.copyfile(src, dst)
28 shutil.copymode(src, dst)
29 shutil.copystat(src, dst)
30 shutil.copy(src, dst)
31 shutil.copy2(src, dst)
32 shutil.ignore_patterns(*patterns)
33 shutil.copytree(src, dst, symlinks=False, ignore=None)
34 shutil.rmtree(path[, ignore_errors[, onerror]])
35 shutil.move(src, dst)
36 shutil.make_archive(base_name, format,...)

More reference: http://www.cnblogs.com/wupeiqi/articles/4963027.html

 

Link of this Article: Python modular learning (1)

Leave a Reply

Your email address will not be published. Required fields are marked *