“整数是必需的".当open()将文件作为utf-8时? [英] "an integer is required" when open()'ing a file as utf-8?

查看:133
本文介绍了“整数是必需的".当open()将文件作为utf-8时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要在python中用以下行打开的文件:

I have a file I'm trying to open up in python with the following line:

f = open("C:/data/lastfm-dataset-360k/test_data.tsv", "r", "utf-8")

打电话给我错误

TypeError:必须为整数

TypeError: an integer is required

我删除了除那一行以外的所有其他代码,但仍然出现错误.我做错了什么,如何正确打开它?

I deleted all other code besides that one line and am still getting the error. What have I done wrong and how can I open this correctly?

推荐答案

摘录自 open() :

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

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

[...]

可选的buffering参数指定文件的所需缓冲区 大小:0表示未缓冲,1表示行缓冲,任何其他正数 value表示使用(大约)该大小的缓冲区.负面的 缓冲意味着使用系统默认值,通常是 为tty设备缓冲,为其他文件完全缓冲.如果 省略,则使用系统默认值.

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. 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.

您似乎正在尝试传递open()一个字符串,该字符串将文件编码描述为第三个参数.不要那样做.

You appear to be trying to pass open() a string describing the file encoding as the third argument instead. Don't do that.

这篇关于“整数是必需的".当open()将文件作为utf-8时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆