python打开.txt错误文件需要一个整数(get type str)

2024-10-01 02:28:29 发布

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

我从未使用过fromos import *,因此此重复建议无效。请看说明书中的代码。在

我不知道我为什么会遇到这个错误。我原以为用open()方法会很简单,但它不起作用。我有一个.txt文件,我试图打开,我得到了这个错误。在

我不知道为什么它要求一个整数而不是一个字符串来打开一个.txt文件

import os
import spacy
import en_core_web_sm
import plac
from collections import Counter
from __future__ import unicode_literals

file = 'spacy_sample.txt'
with open(file, 'r' )as f:
    '''Do something'''


TypeError                                 Traceback (most recent call last)
<ipython-input-198-b6441a57e84e> in <module>()
----> 1 with open(file, 'r' )as f:
      2     print(f)

TypeError: an integer is required (got type str)

Tags: 文件代码fromimporttxtspacyas错误