【发布时间】:2019-07-31 14:26:33
【问题描述】:
我只想在行中出现特殊字符时才计算行数。
count=0
with open (xvg_input, 'r') as cavity_count:
line_to_end = cavity_count.readlines()
for line in line_to_end:
if "#" in line and "@" in line:
count +=1
print (count)
只想在有特殊字符的时候计算行数。
【问题讨论】:
-
这里有什么问题?你的输入是什么样的?
-
现在您的代码只计算同时具有
@和#的行 -
if re.match("^[a-zA-Z0-9_]*$", line): count+=1 -
@ xaxis label "Frame" @ yaxis label "Volume (Angstroms\S3\N)" @ s0 legend "Total" @ s1 legend "Cavity 1" @ s2 legend "Cavity 2"
标签: python python-3.x file-handling