作家
登录

你需要知道的、有用的Python功能和特点

作者: 来源: 2017-06-06 12:02:46 阅读 我要评论

output 
  •  
  •   
  •  
  • # Original Size: 1022 
  •  
  • # Compressed Size: 423 
  •  
  • # Decompressed Size: 1022  
  • 有可模块叫atexit,它可以让你裹足本运行完后立马履行一些代码。

    你须要知道的、有效的Python功能和特点

    假如你想裹足本履行停止时测量一些基准数据,比如运行了多长时光:

    1. import atexit 
    2.  
    3. import time 
    4.  
    5. import math 
    6.  
    7.   
    8.  
    9. def microtime(get_as_float = False) : 
    10.  
    11.     if get_as_float: 
    12.  
    13.         return time.time() 
    14.  
    15.     else
    16.  
    17.         return '%f %d' % math.modf(time.time()) 
    18.  
    19. start_time = microtime(False
    20.  
    21. atexit.register(start_time) 
    22.  
    23.   
    24.  
    25. def shutdown(): 
    26.  
    27.     global start_time 
    28.  
    29.     print "Execution took: {0} seconds".format(start_time) 
    30.  
    31.   
    32.  
    33. atexit.register(shutdown) 
    34.  
    35.   
    36.  
    37. # Execution took: 0.297000 1387135607 seconds 
    38.  
    39. # Error in atexit._run_exitfuncs: 
    40.  
    41. # Traceback (most recent call last): 
    42.  
    43. #   File "C:\Python27\lib\atexit.py", line 24, in _run_exitfuncs 
    44.  
    45. #     func(*targs, **kargs) 
    46.  
    47. # TypeError: 'str' object is not callable 
    48.  
    49. # Error in sys.exitfunc: 
    50.  
    51. # Traceback (most recent call last): 
    52.  

    53.   推荐阅读

        浅谈Web自适应

      媒介<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> 简单工作简单做-宽度自适应所谓宽度自适应严格来说是一种PC端的自适>>>详细阅读


      本文标题:你需要知道的、有用的Python功能和特点

      地址:http://www.17bianji.com/lsqh/35585.html

    关键词: 探索发现

    乐购科技部分新闻及文章转载自互联网,供读者交流和学习,若有涉及作者版权等问题请及时与我们联系,以便更正、删除或按规定办理。感谢所有提供资讯的网站,欢迎各类媒体与乐购科技进行文章共享合作。

    网友点评
    自媒体专栏

    评论

    热度

    精彩导读
    栏目ID=71的表不存在(操作类型=0)