0

I am trying to get the md5 checksum of some files and write them into a temp file.

import os
import hashlib

PID = str(os.getpid()) 
manifest = open('/temp/tmp/MANIFEST.'+ PID + '.tmp','w') #e.g. MANIFEST.48938.tmp
for elmt in files_input:
    input = open(elmt['file'], "r", 'us-ascii') #'us-ascii' when I ran "file --mime"
    manifest.write(hashlib.md5(input.read()).hexdigest()) 

From this I get a Python error that I haven't able to resolve:

Traceback (most recent call last):
 File "etpatch.py", line 131, in <module>
    input = open(elmt['file'], "r", 'us-ascii')
TypeError: an integer is required

Some people have had this error from doing "from os import *" but I am not doing this nor am I using import * on any other module.

4

1 回答 1

1

的第三个参数应该open()是一个整数:

open(name[, mode[, buffering]])

可选的缓冲参数指定文件所需的缓冲区大小:0 表示无缓冲,1 表示行缓冲,任何其他正值表示使用(大约)该大小(以字节为单位)的缓冲区。负缓冲意味着使用系统默认值,通常对 tty 设备进行行缓冲,对其他文件进行完全缓冲。如果省略,则使用系统默认值。[2]

于 2013-03-18T22:30:20.183 回答