| Page 28 of 38 Prev | Index | Next |
import re
import time
s = time.time()
c = re.compile("Slide.*-.*")
for i in range(3):
n = 0
fp = open("jython-presentation.py", "r")
try:
for line in fp:
if c.search(line):
n += 1
finally:
fp.close()
print "found %02d occurences" % (n)
e = time.time()
print e - s
ex_re.py
Something to note, files are not automatically closed in Jython as they are in CPython.
$ python ex_re.py found 14 occurences found 14 occurences found 14 occurences 0.0106308460236
$ jython ex_re.py found 14 occurences found 14 occurences found 14 occurences 0.29399991035461426