Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

regular expression to extract exception/errors in python code base

by asab (Sexton)
on Sep 09, 2012 at 06:02 UTC ( #992561=perlquestion: print w/ replies, xml ) Need Help??
asab has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Can you guys enlighten me with your knowledge!!! I am in search of regular expressions which extracts out all the possible Errors/exception in python code base

Here is what I came up with

grep -RnH "raise .*Error" *.py grep -RnH "except .*:" *.py

I need to add a preamble to the error messages/warnings/exception in python code. To start with I used above pattern to get the required list of error messages! Any help in making it more complete would be of great help

Thanks

Asab

Comment on regular expression to extract exception/errors in python code base
Download Code
Re: regular expression to extract exception/errors in python code base
by james2vegas (Chaplain) on Sep 09, 2012 at 06:09 UTC
Re: regular expression to extract exception/errors in python code base
by CountZero (Bishop) on Sep 09, 2012 at 07:31 UTC
    Python has regular expressions that are very much "Perl Compatible". is there a reason you cannot use Python REs to do this task?

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

    My blog: Imperial Deltronics

      Not specifically

      I chose perl as its easy to match with RE + More comfortable in Perl

Re: regular expression to extract exception/errors in python code base
by Anonymous Monk on Sep 09, 2012 at 16:40 UTC
    Um, what do they look like (sample input)?

      ack -i "\b(?:raise|except)\b" --python C:\Python25

      ack -i "^\s*(?:raise|except)\s" --python C:\Python25

      But, it seems to me python already has introspection ( Guide to Python introspection ), so this grep/ack probably isn't required, but I perl

        This promises to be the closest that I was looking at

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://992561]
Approved by chacham
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (10)
As of 2014-07-22 11:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (110 votes), past polls