E
elmlish
Hello all,
I'm currently befuddled as to how to efficiently test for a positive re.
match then use the results of that match in a function.
Mostly what I've seen people do is to first test for the match, and then
try matching again to get the results. This would seem to be pretty
inefficient to me.
I've tried making the match, then sending it to a variable, then testing
if the variable is good and then finally using it, but this still seems
overkill.
I'm also trying to use this in list comprehensions, mostly because they
are kind of fun. What I've got right now looks something like this.
This is a small test, but what I will be looking for various matches in
is a large special purpose text file.
Does anyone have input on how something like this _should_ be done?
thanks,
I'm currently befuddled as to how to efficiently test for a positive re.
match then use the results of that match in a function.
Mostly what I've seen people do is to first test for the match, and then
try matching again to get the results. This would seem to be pretty
inefficient to me.
I've tried making the match, then sending it to a variable, then testing
if the variable is good and then finally using it, but this still seems
overkill.
I'm also trying to use this in list comprehensions, mostly because they
are kind of fun. What I've got right now looks something like this.
[<_sre.SRE_Match object at 0x11e218>]alist = ['boo','hoo','choo']
[re.match('choo',line) for line in calist if re.match('choo',line)]
This is a small test, but what I will be looking for various matches in
is a large special purpose text file.
Does anyone have input on how something like this _should_ be done?
thanks,