python - 为什么使用 Python 读取 .txt 文件会导致控制台出现空白行?
问题描述
我正在阅读 .txt 文件的教程的一部分。我按照说明键操作键,但我的控制台日志返回一个空行。
有谁知道可能会发生什么?
employee_file = open('employees.txt', 'r')
print(employee_file.readline())
employee_file.close()
解决方案
试试这样:
with open ('employees.txt') as file :
for line in file :
print (line)
推荐阅读
- php - 如何使用错误信息关闭 Laravel 节目?
- php - PHP 内爆值
- javascript - 在 iframe 上打开 Bootstrap 模态窗口
- python-3.x - tkinter 从一个单独的类中调用祖父母实例变量时出错
- excel - vba 输入公式引用另一个动态工作表中的单元格
- javascript - 解析 JSON 文件时出错 - 对象不正确
- google-bigquery - 数据仓库中 BigQuery 表的归档解决方案
- kotlin - 我应该在 Kotlin 数据类中编写 toJson 还是 fromJson 方法?
- php - 如何获取数据并显示到 Carousel - Bootstrap 4 & PHP
- java - 将数据存储在一组枚举对象中