Python:TypeError:需要整数

2024-06-09 10:29:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试获取一些文件的md5校验和并将它们写入临时文件。在

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()) 

由此我得到一个我无法解决的Python错误:

^{pr2}$

有些人在执行“from os import*”时出现了这个错误,但我没有这样做,也没有在任何其他模块上使用import*。在


Tags: 文件importinputos错误asciiopenpid
1条回答
网友
1楼 · 发布于 2024-06-09 10:29:49

^{}的第三个参数应为整数:

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

The optional buffering argument specifies the file’s desired buffer size: 0 means unbuffered, 1 means line buffered, any other positive value means use a buffer of (approximately) that size (in bytes). A negative buffering means to use the system default, which is usually line buffered for tty devices and fully buffered for other files. If omitted, the system default is used. [2]

相关问题 更多 >