Werner
2014-05-23 11:30:54 UTC
Hi,
I like to parse many .py files and check if any of the following is
present in it:
test = """# Tags: phoenix-port, unittest, documented, py3-port"""
A file might or might not have this comment line somewhere at the top,
and it might have one or more of the tags.
I like to report on the file name and what tags are present in it, the
use of this is a check list of what modules have been converted/been done.
On the above test string I tried this, but it only reports on the first.
allTags = pp.Literal("# Tags:") +\
pp.Literal("phoenix-port").setResultsName('phoenix') |\
pp.FollowedBy("unittest").setResultsName('test') |\
pp.FollowedBy("py3-port").setResultsName('py3') |\
pp.FollowedBy("documented").setResultsName('doc')
result = allTags.parseString(test)
print(result)
The other problem I have when using 'parseFile' is how to tell it to
ignore everything before or after, or even all if the '# Tags:' line is
not present.
Hopefully someone can push me in the right direction.
Werner
I like to parse many .py files and check if any of the following is
present in it:
test = """# Tags: phoenix-port, unittest, documented, py3-port"""
A file might or might not have this comment line somewhere at the top,
and it might have one or more of the tags.
I like to report on the file name and what tags are present in it, the
use of this is a check list of what modules have been converted/been done.
On the above test string I tried this, but it only reports on the first.
allTags = pp.Literal("# Tags:") +\
pp.Literal("phoenix-port").setResultsName('phoenix') |\
pp.FollowedBy("unittest").setResultsName('test') |\
pp.FollowedBy("py3-port").setResultsName('py3') |\
pp.FollowedBy("documented").setResultsName('doc')
result = allTags.parseString(test)
print(result)
The other problem I have when using 'parseFile' is how to tell it to
ignore everything before or after, or even all if the '# Tags:' line is
not present.
Hopefully someone can push me in the right direction.
Werner