diff --git a/src/scripts/pycompare.py b/src/scripts/pycompare.py
index b253da6682e141465dfa56690cf8b08ca97a5071..3720701751ae34a02a30326acf7473cf00b85721 100755
--- a/src/scripts/pycompare.py
+++ b/src/scripts/pycompare.py
@@ -166,6 +166,7 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=4, log_file=None):
     f_line = f_line.replace("D-","E-").replace("D+","E+")
     ref_format = "    <div><span style=\"font-weight: bold; color: rgb(125,125,125)\"><pre><code>{0:%ds}"%num_len
     ref_line = (ref_format + ": {1:s}</code></pre></span></div>\n").format("ORIG", f_line[:-1])
+    log_line = ""
     if (f_line == c_line):
         if log_file is not None:
             if (config['full_log']):
@@ -189,9 +190,10 @@ def compare_lines(f_line, c_line, config, line_num=0, num_len=4, log_file=None):
         if (len(f_groups) == len(c_groups)):
             severities = mismatch_severities(f_groups, c_groups, config)
             if log_file is not None:
-                num_format = "    <div><pre><code>{0:0%dd}"%num_len
-                log_line = (num_format + ": ").format(line_num)
-                log_line = log_line + c_line[0:c_starts[0]]
+                if (len(severities) > 0):
+                    num_format = "    <div><pre><code>{0:0%dd}"%num_len
+                    log_line = (num_format + ": ").format(line_num)
+                    log_line = log_line + c_line[0:c_starts[0]]
             for si in range(len(severities) - 1):
                 if (severities[si] == 1): noisy += 1
                 elif (severities[si] == 2): warnings += 1