python - 如何在 Python 中读取每行文本并将其转换为 ASCII 小数?
问题描述
我试图做的事情:
f = open('j:/text.txt', 'r')
lines = []
for line in f:
lines.append(line)
print (''.join(str(ord(c)) for c in line))
print (line)
print (lines)
但这仅转换最后一行并忽略前面的行。
解决方案
我认为您想打印每一行的 ASCII 等效项和行本身。将前两个print
语句放入for
循环中(缩进一次)。
f = open('j:/text.txt', 'r')
lines = []
for line in f:
lines.append(line)
print (''.join(str(ord(c)) for c in line))
print (line)
print (lines)
推荐阅读
- javascript - 是否有任何内置函数,例如在 javascript 中查找所有内容?
- javascript - 这个循环是同步执行的吗?
- python - Tkinter,xlwt,尝试编辑已在循环中创建的检查按钮
- ios - 表格视图滚动后播放/暂停按钮图像发生变化
- plugins - Ionic 4 PWA - 电容器和相机插件怪异的行为
- flutter - Dart 流数据长度检查
- c# - 为什么 Visual Studio 会引发错误,阻止添加视图?
- css - 现在保留这些“-webkit-”“-moz-”“-o-”“-ms-”前缀有多大必要?(截至 2019 年 12 月)
- mongodb - 我如何查询文本的一部分并使用猫鼬获取全部内容?
- reactjs - React - 如何仅在某些确切的路由路径上渲染组件?