DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5的解決辦法


今天在學習python的md5模塊的時候,做練習,遇到DeprecationWarning: the md5 module is deprecated; use hashlib instead
  import md5的警告;

# /usr/bin/python
# -*- coding:utf-8 -*-

import md5
hash = md5.new()
hash.update('spam,spam,and egges')
print repr(hash.digest())

執行結果為:

解決辦法:

# /usr/bin/python
# -*- coding:utf-8 -*-
try:
    import hashlib
    hash = hashlib.md5()
except ImportError:
    # for Python << 2.5
    import md5
    hash = md5.new()
hash.update('spam,spam,and egges')
print repr(hash.digest())

如代碼所示,我使用的python版本是2.6.6,所以會有警告,如果是2.5之前的版本就不會有了。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM