[英]Using Pycharm I don't get any output once code is run, just Process finished with exit code 0
So pretty much, I have a directory that contains many of 2 types of text files, a bunch of files that begin with "summary_" and a bunch of files that begin with "log". 差不多,我有一个目录,其中包含2种类型的文本文件,一堆以“ summary_”开头的文件和一堆以“ log”开头的文件。 All these text are in the same directory. 所有这些文本都在同一目录中。 For now I don't care about the "log" text files, I only care about the files that start with "summary". 现在,我不关心“日志”文本文件,只关心以“摘要”开头的文件。
Each "summary" file contains either 7 lines of text or 14 lines of text. 每个“摘要”文件包含7行文本或14行文本。 At the end of each line it will say either PASS or FAIL depending on the test result. 在每一行的末尾,将根据测试结果显示“通过”或“失败”。 For the test result to be passing all 7 or 14 lines have to say "PASS" at the end. 为了使测试结果通过所有7或14行,最后必须说“ PASS”。 If one of those lines have just one "FAIL" in it, The test has failed. 如果其中一行仅包含一个“ FAIL”,则测试失败。 I want to count the number of passes and failures. 我想计算通过和失败的次数。
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()
I don't know about within Pycharm, but the following seems to work without it: 我不了解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.