random module os module

Random # 
# Import Random
# random.random () # 0 and less than or greater than a decimal between 1
# the random.randint () # 1 and less than or equal to an integer between. 3
# random.randrange () greater than or equal to 1 and # less than the integer. 3
# the random.choice ([. 1, '23 ',' [45] ']) take only a #
# random.sample ([1, '23' , '[45]'], 2) take list # combination of any two
# random.uniform (1,3) # 1 is greater than a decimal less than 3
# Import Random
# Print (random.random ())
# Print (the random.randint (l, 3))
# Print (random.randrange (l, 3))
# Print (The random.choice ([. 1, '23 ',' [45] ']))
# Print (random.sample ([. 1, '23', '[45 ] '], 2))
# Print (random.uniform (l, 3))
' ''
.09330761008045674
. 1
. 1
[45]
[ '[45]',. 1]
. 1.9699491181751925
'''
# import random
L = # [1,2,3,4,5]
# random.shuffle (L) shuffling #
# Print (L) # [. 3, 2,. 4,. 5,. 1]
# Import Random
# DEF make_code (n-) :
# = RES ''
# for I in Range (n-):
# STR = S1 (the random.randint (0,9))
# S2 = CHR (the random.randint (65, 90,))
# = RES + The random.choice ( [S1, S2])
# return RES
#
# Print (make_code (. 4)) YM1J #

# OS module
# Import OS
# the os.getcwd () # Get the current working directory, i.e., the current working directory path python script
# os.chdir ( "dirname") # script to change the current working directory, under the equivalent of cd shell
# os.curdir # returns the current directory ( '.')
# # os.pardir get the current directory's parent directory string name ( '..')
# os.makedirs ( 'dirname1 / dirname2' ) # may generate recursive transfer multilayer
# os.removedirs ( 'dirname1') # If the directory is empty, delete, and recursively to the parent directory, it should also empty, delete, and so on
# Os.mkdir ( 'dirname') # generate single-level directory, the equivalent of the shell dirname mkdir
# os.rmdir ( 'dirname') # delete the single-level directory, if the directory is not empty can not be deleted, error, equivalent to the shell dirname rmdir
# os.listdir ( 'dirname') # list all files and subdirectories in the specified directory, including hidden files, in a parallel fashion print
# os.remove () # delete a file
# os.rename ( "oldname", "newname") # rename file / directory
# os.stat ( 'path / filename' ) # get the file / directory information
# os.sep # output operating system-specific path separator is "\\" lower win, Linux of the "/"
# # os.linesep output line terminator current platform used for "\ n \ t" under the win, as "\ n" under the Linux
# # the os.name output string indicating the current use internet, win -> 'NT', Linux -> 'the POSIX'
# os.system () # run shell commands, direct display
# os.environ # acquisition system environment variables
# os.path.abspath (path) # return path normalized absolute path
# os.path.split (path) # the path into the directory and file name of the tuple returned
# os.path.dirname (path) # Returns the directory path, in fact, the first element os.path.split (path) of
# Os.path.basename (patn) # Returns the last file name path, if path to / \ or end, it will return a null value, namely os.path.split (path) of the second element
# os.path .exists (path) # If the path exists, returns Ture, if the path does not exist, return False
# os.path.isabs (path) # If the path is the absolute path to return Ture
# os.path.isfile (path) # If the path is an existing file, return Ture, otherwise it returns False
# os.path.isdir (path) # If the path is an existing directory, returns Ture, otherwise it returns False
# os.path.join (path1 [, path2 [,. ..]]) # combination of a plurality of paths after the return, a parameter before the first absolute path is ignored
# os.path.getatime (path) # returns the path to the file or directory is last access time
# os. path.getmtime (path) # return path points to a file or directory last modified
# os.path.getsize (path) # return path size
# Import os
# Print (the os.stat (r'D: \ python13 of \ module '))
' ''
os.stat_result (The st_mode = 16895, st_ino = 8162774324621281, the st_dev = 79,899,118, st_nlink =. 1, the st_uid = 0, st_gid = 0, the st_size = 0, the st_atime = 1576237599, the st_mtime = 1576237599, 1576197311 st_ctime =)
'' '
# Print ( os.stat (r'D: \ python13 of \ module ') .st_size) # 0
# Print (os.stat (r'D: \ python13 of \ s1.log'))
# Print (the os.stat (R & lt ' D: \ python13 of \ s1.log ') the st_size).
# Print (os.path.getsize (r'D: \ python13 of \ s1.log'))
'' '
os.stat_result (The st_mode = 33206, st_ino = 5066549580809765, the st_dev = 79,899,118, st_nlink =. 1, the st_uid = 0, st_gid = 0, the st_size = 237, the st_atime = 1,576,067,616, the st_mtime = 1,576,067,616, st_ctime = 1576067376)
237
237
'' '
# Import OS
# the os.system (' tasklist ' ) # see what is running too many processes on the system, as well as the beginning of garbled
# res = os.System ( 'tasklist')
# Print (RES) more than a rearmost # 0
# print(os.path.split(r'D:\python13期\s1.log'))
# print(os.path.dirname(r'D:\python13期\s1.log'))
# print(os.path.basename(r'D:\python13期\s1.log'))
'''
('D:\\python13期', 's1.log')
D:\python13期
s1.log
'''
# import os
# print(os.path.isabs(r'C:\\a123sx')) # python
# print(os.path.isabs(r'/rooy/a123sx')) # Linux
'''
True
True
'''
# import os
# print(os.path.join('C:','D:\\','dir1','a.txt')) # D:\dir1\a.txt
# import os
# print(os.path.normcase(r'D:/python13期\S1.log'))
''''' 'd: \ python13 of \ s1.log
Only useful on Windows systems uppercase to lowercase left and right slash slash changed Linux will return intact


# Print (os.path.normpath ( 'D: // windows \\ python13 of S1.log \\ ../ a.txt \\'))
# Print (os.path.normcase ( 'D: // Windows \\ \\ python13 of s1.log ../ a.txt \\ '))
' ''
D: \ Windows \ python13 of \ a.txt
D: \\ Windows \ python13 of \ s1.log \ .. \ a.txt
'' '
# Import OS
# Print (os.path.dirname (os.path.abspath with (__ file__)))
# Print (os.path.dirname (os.path.dirname (os.path.abspath with (__ file__ ))))
'' '
D: \ python13 of \ module
D: \ python13 of
' ''
# Import os
# D: \ python13 of \ module \ os module Random module .py \ .. \ ..
# Print (os .path.join (
# os.path.abspath with (__ file__),
# '..',
# '..'
#))
# = base_dir os.path.normpath (the os.path.join(
# os.path.abspath(__file__),
# '..',
# '..'
#))
# Print (base_dir) # Cross-platform
'' '
D: \ python13 of \ modules \ random module os module .py \ .. \ ..
D: \ python13 period
'' '

Guess you like

Origin www.cnblogs.com/0B0S/p/12037251.html