今天在學習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之前的版本就不會有了。