readlines() 在 Jupyter Notebook 中不起作用
readlines() not working in Jupyter Notebook
新手级别 Python 学习者,正在使用新下载的 macos Catalina Python 3.8 安装,使用 Jupyter Notebook。
readlines() 返回所有带有 \n 分隔符的行,而不是单独的行。
foo = open('foo.txt')
foo.seek(0)
foo.readlines()
Returns:
['Something on line 1.\n', 'Something on line 2.\n', 'Something on line 3.']
foo.txt 文件如下所示:
Something on line 1.
Something on line 2.
Something on line 3.
我是否认为这不是预期的行为?我在这里找不到类似的查询。谢谢。
编辑 - 这是它在本教程的 Jupyter Notebook 中的显示方式。也许这是一个笔记本设置?
Am I right in thinking this is not expected behaviour?
不,这是任何 python 编辑器都应该发生的事情。
readlines() is returning all one line with \n, separators instead of individual lines.
如果你想要多行,就这样做:
foo = open('foo.txt')
foo.seek(0)
foo.read()
新手级别 Python 学习者,正在使用新下载的 macos Catalina Python 3.8 安装,使用 Jupyter Notebook。
readlines() 返回所有带有 \n 分隔符的行,而不是单独的行。
foo = open('foo.txt')
foo.seek(0)
foo.readlines()
Returns:
['Something on line 1.\n', 'Something on line 2.\n', 'Something on line 3.']
foo.txt 文件如下所示:
Something on line 1.
Something on line 2.
Something on line 3.
我是否认为这不是预期的行为?我在这里找不到类似的查询。谢谢。
编辑 - 这是它在本教程的 Jupyter Notebook 中的显示方式。也许这是一个笔记本设置?
Am I right in thinking this is not expected behaviour?
不,这是任何 python 编辑器都应该发生的事情。
readlines() is returning all one line with \n, separators instead of individual lines.
如果你想要多行,就这样做:
foo = open('foo.txt')
foo.seek(0)
foo.read()