struct module & subprocess module

struct module:

  It's that use >>>

Import struct   # introduced first module 

res = ' ncjewgfjsdbvdhj '   # arbitrary value 
Print (len (res))   # 15 just to show the length of the original res of 

RES1 = struct. Pack ( 'I', len (res) )   # packing , fixing i-mode, len (RES) 
Print (len (RES1))   # next. 4 i modes to 4, q modes are. 8 

RES2 = struct. the unpack ( ' i ' , RES1 ) [0]   # unpacked , back certain to index the [0]
 Print (RES2)

 

subprocess module:

  Mediated one so used >>>

Import The subprocess   # Import Module 
# module can automatically execute your command input in a terminal channel, and returns the result of execution
cmd = INPUT ( ' >>> ' ) .strip () obj = The subprocess. the Popen ( cmd , the shell = true, stdout = subprocess.PIPE, stderr = subprocess.PIPE) # fixed wording, the first parameter is the command input RES = obj. stdout .read () # result bytes type RES1 = obj. stderr .read () # the type of result bytes Print (RES, RES1)

 

Guess you like

Origin www.cnblogs.com/pupy/p/11323812.html