python - 删除除带有 % 的行之外的所有内容并删除 %
问题描述
例子:
1
Yuumi
78.57%
2075
1956
0.64
62.8
Thresh
77.59%
1079
917
0.83
19.3
Braum
76.00%
1868
1315
1.44
38.0
我希望它是:
78.57
77.59
76.00
(带 % 的数字)
尝试在论坛中查找并使用文件和内容中的 readlines 但我是初学者并且无法使其在 python 中正常工作,在此先感谢
解决方案
with open('path/to/the/file') as fd:
for line in fd:
if '%' in line:
print(line.strip().replace('%', ''))
或者您可以在 shell 中执行此操作:
grep "%" filename | sed 's/%//g' >newfile
推荐阅读
- xml - XSLT 1.0:以不同的步骤重新排列 xml(xsl 模板)
- group-by - HQL 子查询替换
- vba - VBA:从多个工作表复制粘贴多个工作簿
- android - ProgressBar 对话框显示时底部导航卡住
- php - 想要删除 php 中最后一个“/”之后的所有内容
- c# - CultureInfo : 显示具有自己文化的语言
- javascript - 怎么做 $(element).function({})
- javascript - 当从网页进行 jQuery ajax 调用时调用内容脚本中的函数
- javascript - 展开网页上的所有可折叠部分
- javascript - 我在Promise的then()方法中执行Promsie.all(),Promsie.all()中的方法先执行。代码如下