- 论坛徽章:
- 4
|
使用:
python get_md5.py --input your_input_file --output out.txt
将下述代码保存为 get_md5.py- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- __author__ = 'shengwei ma'
- __author_email__ = 'shengweima@icloud.com'
- import sys
- import getopt
- input_file = ""
- output_file = ""
- try:
- opts, args = getopt.getopt(sys.argv[1:], "h", ["input=", "output="])
- except getopt.GetoptError as err:
- print(str(err))
- for op, value in opts:
- if op == "--input":
- input_file = value
- elif op == "--output":
- output_file = str(value)
- elif op == "-h":
- print("python get_md5.py --input your_input_file --output out.txt")
- sys.exit()
- def md5(str):
- import hashlib
- import types
- if type(str) is types.StringType:
- m = hashlib.md5()
- m.update(str)
- return m.hexdigest()
- else:
- return ''
- with open(output_file, 'w') as f:
- f.write(md5(input_file) + '\n')
复制代码 |
|