zoukankan      html  css  js  c++  java
  • [py]py常用模块小结

    - python md5校验: https://blog.csdn.net/linda1000/article/details/17581035
    import hashlib
    hashlib.md5(fcont).hexdigest()
    
    - python改变当前目录: https://blog.csdn.net/flying881114/article/details/6224266
    os.chdir("目标目录")
    os.getcwd("目标目录")
    
    - python执行命令: http://blog.51cto.com/zhou123/1312791
    >>> import commands
    >>> a,b = commands.getstatusoutput('ls')
    
    
    
    
    pip: https://pypi.org/project/pip
    setuptools: https://pypi.org/project/setuptools/
                https://blog.csdn.net/DongGeGe214/article/details/52199439
    
                
    - chardet使用:https://www.liaoxuefeng.com/wiki/0014316089557264a6b348958f449949df42a6d3a2e542c000/001510905171877ca6fdf08614e446e835ea5d9bce75cf5000
    pip install chardet
    with open('1.txt') as f:
        upload_text=f.read()
    char_check = chardet.detect(upload_text)
    file_code = char_check['encoding']
    
    - pyhon转码:
    upload_text = upload_text.decode(file_code).encode("utf-8")
    
    
    
        
    - python获取参数: https://blog.csdn.net/csdn15698845876/article/details/74909089
    import sys
    filename = sys.argv[0]
    arg1 = sys.argv[1]
    arg2 = sys.argv[2]
    
    - python获取文件和路径: https://blog.csdn.net/scelong/article/details/6971917
    os.path.basename()
    os.path.dirname()
    
    - python拷贝文件: https://www.cnblogs.com/sld666666/archive/2011/01/05/1926282.html
    import shutil
    shutil.copy(sourceDir,  targetDir)
    
    
    - Python中进行Base64编码和解码: https://blog.csdn.net/lxdcyh/article/details/4021476
    >>> import base64
    >>> s = '我是字符串'
    >>> a = base64.b64encode(s)
    >>> print a
    ztLKx9fWt/u0rg==
    >>> print base64.b64decode(a)
    
    - python的bz2压缩: https://python-documentation-cn.readthedocs.io/en/latest/library/bz2.html
    bz2.compress(data)
    bz2.decompress(data)
    
    
    def get_file_code(file_path):
        "打印路径文件内容base64"
        import chardet
        with open(file_path) as f:
            raw_data = f.read()
        char_check = chardet.detect(raw_data)
        file_code = char_check['encoding']
        return file_code
    
  • 相关阅读:
    python_levenshtein 的安装和使用
    接口测试困难
    pycharm修改windows的IP
    Excel读取,修改,新建
    appium混合应用的处理
    冒泡排序
    选择排序
    插入排序
    python中两种退出方式os._exit(),sys.exit()
    二分查找
  • 原文地址:https://www.cnblogs.com/iiiiiher/p/9229424.html
Copyright © 2011-2022 走看看