python - AttributeError: '_io.BufferedReader' 对象没有属性 'strip'

标签 python attributeerror

我遇到了这个错误。为什么?

File "/k.py", line 257, in deskJ
    eremuak = aFileLine.strip().split('\t')
AttributeError: '_io.BufferedReader' object has no attribute 'strip'

代码

def deskribapenaJaso(self, aFileLine):
    eremuak = aFileLine.strip().split('\t')
    print(eremuak) #printNothing

aFileLine = 它是文件的 X 行

最佳答案

您正在对打开的文件对象使用 str 方法。

只需在文件对象上调用 list() 即可将文件作为行列表读取:

with open('goodlines.txt') as f:
    mylist = list(f)

关于python - AttributeError: '_io.BufferedReader' 对象没有属性 'strip',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36715639/

相关文章:

python - 将字符串数据传递给 matplotlib API 时会绘制什么?

Python mechanize 不处理表单异常

python - Scrapy shell 返回无响应

python-3.x - 即使模块实际上包含脚本,模块也没有属性

python Nose : setting description attribute on generated tests

python - setattr 和 getattr 方法

python - tensorflow ,凯拉斯。使用 bool 数组作为输入构建模型

python - Django 中基于类的 View 上的 login_required 装饰器

Python -- Pygame 属性错误 : int object has no attribute 'draw'

python - 在 tensorflow 中一次从张量获取多个索引中的值