The various packages python

 

Because of the need to address different needs, therefore, python prepared a rich set of modules. As long as import can be used, simple and efficient.

>>> collection module

  >> Named tuples (namedtuple), you can pass parameters to specify the location of 11, after the assignment, you can call alone can be used to store coordinate location

  >> Queue (queue), go to Advanced

>> deque

>> ordered dictionary (OrderDict), remember the order of addition of dictionary elements

>> defaultdict () The default value is set in the key of the dictionary

The number of occurrences >> counter, single-character string of statistics

 

 

Module >>> time: time taken, formatted output time,

 

 


>>> random is an interesting module, all with random probability relevant places, can be used. (Below: get Code)

 

>>> os: can realize interact with the operating system.

  os.mkdir ( 'xxx filename'): Create a folder

  os.path.exists ( 'folder path'): determining whether there is a folder

  The os.path.isfile ( 'file path'): determining whether the file exists

  os.rmdir ( 'folder path'): You can only delete empty folders

  os.path.dirname (__ file__): Gets the path of the current file

  the os.path.join ( 'folder path 1', 'folder path 2'): stitching path

  the os.listdir ( 'folder path'): Displays the current folder and all file names

  the os.chdir ( 'folder path'): switching all of the current directory

  os.getcwd (): Get all the current directory

  os.path.getsize ( 'file path'): Get File Size, in bytes

>>> sys interact with the program

  sys.path.append('文件夹路径'):可以将指定文件夹路径添加到程序环境变量中,
>>>json不同语言编写的程序之间,进行数据传递的工具

  因为语言之间设计的不同,他能转换的数据类型是有限的.

  序列化:将字符串转换成其他数据类型

  dumps:转换后,可以写入文件,也可以直接赋值给变量.进行传递

  dump:转换后,需要以wb或rb的形式写入文件

  反序列化:将其他数据类型转换成字符串

  loads:将变量名或文件中读取的内容反序列化

  load:将文件中读取的内容反序列化

>>>pikle是python内部专用的其他语言无法识别,可以转换python中的所有数据类型

  dump,load,dumps,loads.操作方法和json一样.好处之一就是可以保存python对象

>>>subprocess:子进程序,可以调用cmd命令行,执行命令,并返回结果

while True:
    cmd = input('cmd>>>:').strip()
    import subprocess
    obj = subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    # print(obj)
    print('正确命令返回的结果stdout',obj.stdout.read().decode('gbk'))
    print('错误命令返回的提示信息stderr',obj.stderr.read().decode('gbk'))

 

Guess you like

Origin www.cnblogs.com/hellozizi/p/11209462.html