3 ms·
Here' an ancient hack that showed how that might look like - http://dalkescientific.com/Python/python4ply-tutorial.html#matching http://dalkescientific.com/Pyth
by eesmith 4y ago
Here' an ancient hack that showed how that might look like - http://dalkescientific.com/Python/python4ply-tutorial.html#matching http://dalkescientific.com/Python/python4ply-tutorial.html#m... .
count = 0
t1 = time.time()
for line in open("nucleosome.pdb"):
if line =~ m/(ATOM |HETATM)/:
count += 1
print count, "atoms in", time.time()-t1, "seconds"
It used it own PLY-based parser to generate the Python AST.
None of it would work now. :)
- eesmith 4y agoI realize now how much of a hack it is. The portion 'm/(ATOM |HETATM)/' could be part of valid Python expression, as: >>> ATOM = HETATM = 1 >>> m = 2 >>> m/(ATOM |HETATM)/1 2.0 so either m// is enabled only after =~, or there has to be some way to recognize the lexically correct match term -- something more powerful than the "m/[^/]*/[a-z]*" used here.