python - 在python中查找并检查行
问题描述
def check():
with open('cefuse.txt') as f:
datafile = f.readlines()
for line in datafile:
if line starts with 'Word 30' and contains only 0
return True
return False
我想检查 .txt 文件中的一行。如果它仅包含 0,则 retcode 将 1 否则为 0。这是我的行:Word 30 : 0x01312e58
解决方案
我希望你期待这样。
def check():
with open('cefuse.txt') as f:
datafile = f.readlines()
for line in datafile:
if line startswith('Word 30') and '0' in line:
return True
return False
推荐阅读
- json - 雪花解析多行 JSON
- javascript - js 类语法在 node_modules 库中不起作用
- fusion360 - 两条相交的线不会产生新的形状,为什么?
- node.js - 在 MongoDataSource (apollo server) 中使用 String id 而不是 ObjectId
- kivy - Kivy 不再允许调整窗口大小?
- mysql - mysqldump:运行命令 php artisan schema:dump 时,laravel 中的未知变量“set-gtid-purged=OFF”
- json - 我需要帮助在 arduino 上使用 indexof ()
- css - 有没有办法修复 katex 溢出?
- python-3.x - 正则表达式在英镑符号后捕获数字 - 用逗号和未捕获空格后的数量
- django - Django 通用表单集 ManytoManyField 不是已清理数据的一部分