I am using regular expressions to recognize the lines containing \begin{frame}
in .tex
files. Below is my code:
#!/usr/bin/python
import re,sys
def isEven(num):
res = [False,True][bool(num % 2 == 0)]
return res
textin = open(sys.argv[1]).readlines()
nline = 0
pat = r'\b\begin{frame}\b'
for line in textin:
line = line.strip(' ')
#print 'Test: ',line[:13]
if re.match(pat,line):
print 'here'
nline += 1
if isEven(nline):
print '%',line.strip('\n')
else:
print line.strip('\n')
This program aims to add the character '%' before the lines in the tex file if the number of frames is even. In other words, I want to comment the slides which the slide number is even.
Do you know what is the wrong in the pattern?