![](/img/trans.png)
[英]when I run this code in Pycharm i didn't get any outputs simply it shows---— process finished with exit code 0. please help me with this issue
[英]Using Pycharm I don't get any output once code is run, just Process finished with exit code 0
差不多,我有一个目录,其中包含2种类型的文本文件,一堆以“ summary_”开头的文件和一堆以“ log”开头的文件。 所有这些文本都在同一目录中。 现在,我不关心“日志”文本文件,只关心以“摘要”开头的文件。
每个“摘要”文件包含7行文本或14行文本。 在每一行的末尾,将根据测试结果显示“通过”或“失败”。 为了使测试结果通过所有7或14行,最后必须说“ PASS”。 如果其中一行仅包含一个“ FAIL”,则测试失败。 我想计算通过和失败的次数。
import os
import glob
def pass_or_fail_counter():
pass_count = 0
fail_count = 0
os.chdir("/home/dario/Documents/Log_Test")
print("Working directory is ") + os.getcwd()
data = open('*.txt').read()
count = data.count('PASS')
if count == 7 or 14:
pass_count = pass_count + 1
else:
fail_count = fail_count + 1
print(pass_count)
print(fail_count)
f.close()
pass_or_fail_counter()
我不了解Pycharm内部的内容,但以下内容似乎可以解决此问题:
import os
import glob
def pass_or_fail_counter(logdir):
pass_count, fail_count = 0, 0
for filename in glob.iglob(os.path.join(logdir, '*.txt')):
with open(filename, 'rt') as file:
lines = file.read().splitlines()
if len(lines) in {7, 14}: # right length?
if "PASS" in lines[-1]: # check last line for result
pass_count += 1
else:
fail_count += 1
print(pass_count, fail_count)
pass_or_fail_counter("/home/dario/Documents/Log_Test")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.