python - 如何访问字节数组文件的某些字节?
问题描述
我有一个文本文件,其中每一行都包含 bytearray。我想打印第二个和第三个数字等于 34 的行并计算它们以显示此文件中存在多少。我的 file.txt 的内容是:
12345678
12678364
90783457
95349387
python 脚本应该打印该文件的第一行和最后一行。为此,我写道:
count =0
with open ('file.txt', 'rt') af in_file:
for line in in_file:
if line[2:4]=='34': #problem is in this line. this line prints line numbers not value of each line.
print("line: ", line)
count +=1
print("count: ", count)
我不知道如何编写该if
语句才能正常工作。
解决方案
推荐阅读
- android - Flutter CameraControl - 如何以指定的持续时间拍照
- cuda - 在 cuda 中,是否可以从具有预期序列的稀疏数组中写入密集数组?
- verilog - 在顶层 tb 访问内部模块(tb.dut.ab)apb 接口
- docker - 如何从本地目录复制到名为卷的 docker 并将其挂载到 NGINX 容器上?
- ruby-on-rails - Rails:类作为哈希值?
- r - 为变量重要性和绘图实现 varImp
- flutter - 按下按钮时 Flutter DraggableScrollableSheet 未显示
- visual-studio-code - editor.wordWrap 在奇怪的位置包装文本
- r - 如何匹配模式不同的三列?
- sql - 具有 NULL 值的简单 1:1 映射表的主键?