http://www.perlmonks.org?node_id=992561

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

Replies are listed 'Best First'.
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