Task
Your mission is to create a program that reviews Python code. The solution can be written in any language!
It must take input that contains python code. The program must add # This is not pythonic!
before each block of non-whitespace lines.
Input
- The data can be entered via stdin.
- The data will contain at least 3 lines with one blank one in between them.
Minimum input example.
print "Hello World!"
Print "Bye World!"
Sample Input
from os.path import abspath
lines = []
with open(__file__, 'r') as f:
for line in f:
lines.append(line)
if lines is not None:
newLines = []
hasReviewedBlock = False
for line in lines:
if len(line) > 1: # \n
if hasReviewedBlock == False:
newLines.append("# This is not pythonic!\n")
hasReviewedBlock = True
else:
hasReviewedBlock = False
newLines.append(line)
with open("d:/test.py", 'w') as f:
for line in newLines:
f.write(line);
Output
Output has to be written to STDOUT or closest alternative.
Sample Output
# This is not pythonic!
from os.path import abspath
# This is not pythonic!
lines = []
with open(__file__, 'r') as f:
for line in f:
lines.append(line)
# This is not pythonic!
if lines is not None:
# This is not pythonic!
newLines = []
hasReviewedBlock = False
# This is not pythonic!
for line in lines:
if len(line) > 1: # \n
if hasReviewedBlock == False:
newLines.append("# This is not pythonic!\n")
hasReviewedBlock = True
else:
hasReviewedBlock = False
# This is not pythonic!
newLines.append(line)
with open("d:/test.py", 'w') as f:
for line in newLines:
f.write(line);
Scoring:
Lowest number of bytes wins. -5 bytes if your program can be used as valid input.