six ---- Python2 and Python3 coding helper library

metaclass

参考:

两种方法:

  1. six.with_metaclass

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    
    import six
    
    
    class MyMeta:
        def __new__(self, cls, name, bases, attrs):
            pass
    
    
    class MyBase:
        pass
    
    
    class MyClass(six.with_metaclass(MyMeta, MyBase)):
        pass
    • 接口说明

      • six.with_metaclass(MetaClass, *otherBases)
  2. six.add_metaclass

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    
    import six
    
    
    class MyMeta:
        def __new__(self, cls, name, bases, attrs):
            pass
    
    
    class MyBase:
        pass
    
    @six.add_metaclass(MyMeta)
    class MyClass(myBase):
        pass

字符串类型 str

six.text_type

7z

解压缩

不保持目录

  • 在当前目录导出
  • 命令

    1
    
      7z e ./pack.zip

保持目录结构

  • 命令

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    
    # 压缩文件结构 mypack.zip
    # -----------------------
    # tei/
    #    file1.txt
    #    file2.txt
    
    # 在当前目录导出
    # 导出结构
    # ------------------------
    # ./tei/
    #     file1.txt
    #     file2.txt
    7z x ./mypack.zip
    
    
    # 制定目录
    # 到处结构
    # -------------------------
    # ./tei/tei/
    #         file1.txt
    #         file2.txt
    7z x ./mypack.zip -otei/ # 指定到处文件夹: ./tei/

tee ---- 文本文件制作工具

优势

  • 相对于 重定向 操作符 > 和 >>

    1. 功能更多
    2. 权限丰富

功能

把 命令行获取到的输入,输出到文件

可以接受的输入类型:

  • stdin
  • stdout
  • Pipe 管道结果

类似 >

  • 管道

    1
    
      echo hello | tee /path/to/my_file.txt
  • heredoc