作家
登录

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

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

  • output => various attempts 
  •  
  • # 9e177ec0-65b6-11e3-b2d0-e4d53dfcf61b 
  •  
  • # be57b880-65b6-11e3-a04d-e4d53dfcf61b 
  •  
  • # c3b2b90f-65b6-11e3-8c86-e4d53dfcf61b  
  • 为了削减反复的情况,你可以应用这两个函数。

    注册Shutdown函数

    1. import hmac,hashlib 
    2.  
    3. key='1' 
    4.  
    5. data=http://developer.51cto.com/art/201706/'a' 
    6.  
    7. print hmac.new(key, data, hashlib.sha256).hexdigest() 
    8.  
    9.   
    10.  
    11. m = hashlib.sha1() 
    12.  
    13. m.update("The quick brown fox jumps over the lazy dog"
    14.  
    15. print m.hexdigest() 
    16.  
    17.   
    18.  
    19. # c6e693d0b35805080632bc2469e1154a8d1072a86557778c27a01329630f8917 
    20.  
    21. # 2fd4e1c67a2d28fced849ee1bb76e7391b93eb12  

    序列化

    你曾经须要将一个复杂的变量存储在数据库或文本文件中吧?你不须要想一个独特的办法将数组或对象格转化为式化字符串,因为Python已经供给了此功能。

    1. import pickle 
    2.  
    3.   
    4.  
    5. variable = ['hello', 42, [1,'two'],'apple'
    6.  
    7.   
    8.  
    9. # serialize content 
    10.  
    11. file = open('serial.txt','w'
    12.  
    13. serialized_obj = pickle.dumps(variable) 
    14.  
    15. file.write(serialized_obj) 
    16.  
    17. file.close() 
    18.  
    19.   
    20.  
    21. # unserialize to produce original content 
    22.  
    23. target = open('serial.txt','r'
    24.  
    25. myObj = pickle.load(target) 
    26.  
    27.   
    28.  
    29. print serialized_obj 
    30.  
    31. print myObj 
    32.  
    33.   
    34.  
    35. #output 
    36.  
    37. # (lp0 
    38.  
    39. # S'hello' 
    40.  
    41. # p1 
    42.  
    43. # aI42 
    44.  
    45. # a(lp2 

        推荐阅读

        浅谈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)