【问题标题】:can i know what's problem in my simple python code when i use readlines?当我使用 readlines 时,我能知道我的简单 python 代码有什么问题吗?
【发布时间】:2022-07-27 00:13:02
【问题描述】:

我是使用 jupyter-lab 的 python 初学者,我正在尝试打开文本文件并希望从文本文件中获取数据。虽然是很简单的代码,但是return很奇怪。

什么问题??????

我的代码:

import os

f=open("C:/Users/dfdfdfd/Desktop/python/list.txt","rt")

lines = f.readlines

lines

----返回-----------------

<function TextIOWrapper.readlines(hint=-1, /)>

【问题讨论】:

  • readlines 是一个函数,而不是f 的属性。你应该叫它f.readlines()
  • 试试f.readlines();您需要调用该方法。

标签: python jupyter-lab


【解决方案1】:

readlines 是可调用的。

with open("C:/Users/dfdfdfd/Desktop/python/list.txt","rt") as f:
    lines = f.readlines()

【讨论】:

    猜你喜欢
    • 2019-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-19
    • 1970-01-01
    • 1970-01-01
    • 2012-05-19
    相关资源
    最近更新 更多