美文网首页
python——模块,调试

python——模块,调试

作者: Jalynn葸 | 来源:发表于2018-05-14 16:04 被阅读58次
    python里常见的标准库
    image.png
    hashlib

    用于加密

    >>> import hashlib
    >>> t = hashlib.md5()
    >>> t.update(b"xijuanxia")
    >>> t.hexdigest()
    'f190571bee15eaa8d04d3f06970dd857'
    
    常用的拓展库
    image.png
    调试

    pdb是基于命令行的调试工具

    python -m pdb some.py
    

    l(list):显示当前代码
    n(next):向下执行一行代码
    c(continue):继续执行代码
    b(break):添加断点
    clear:删除断点
    p(print):打印一个变量的值
    a(args):打印所有的形参数据
    q(quit):推出调试
    r(retrun):快速执行到函数的最后一行

    EPOQUEs-MacBook-Pro:plane epoque$ python -m pdb class.py
    > /Users/epoque/Desktop/plane/class.py(1)<module>()
    -> def getAverage(a,b):
    (Pdb) l
      1  -> def getAverage(a,b):
      2         result = a + b
      3         print("result =%d"%result)
      4         return result
      5     a = 100
      6     b = 200
      7     c = a + b
      8     ret = getAverage(a,b)
      9     print(ret)
    [EOF]
    (Pdb) n
    > /Users/epoque/Desktop/plane/class.py(5)<module>()
    -> a = 100
    (Pdb) l
      1     def getAverage(a,b):
      2         result = a + b
      3         print("result =%d"%result)
      4         return result
      5  -> a = 100
      6     b = 200
      7     c = a + b
      8     ret = getAverage(a,b)
      9     print(ret)
    [EOF]
    (Pdb) c
    result =300
    300
    The program finished and will be restarted
    > /Users/epoque/Desktop/plane/class.py(1)<module>()
    -> def getAverage(a,b):
    (Pdb) b 7
    Breakpoint 1 at /Users/epoque/Desktop/plane/class.py:7
    (Pdb) c
    > /Users/epoque/Desktop/plane/class.py(7)<module>()
    -> c = a + b
    (Pdb) clear
    Clear all breaks? 
    (Pdb) clear 1
    Deleted breakpoint 1
    (Pdb) p a
    100
    (Pdb) p b
    200
    

    IDE:集成开发环境

    交互调试

    进入python或ipython解释器

    import pdb
    pdb.run('testfun(args)')
    
    程序里埋点

    当执行到这句话时就会停止

    import pdb
    pdb.set_trace()
    
    日志调试

    服务器没有停止的情况下可用日志进行热修复

    pep8编码规则

    导入模块的顺序
    1、标准库
    2、第三方库
    3、本地库
    括号里面避免空格
    逗号,冒号,分号之前避免空格
    python3默认是utf-8

    相关文章

      网友评论

          本文标题:python——模块,调试

          本文链接:https://www.haomeiwen.com/subject/gcxjdftx.html