I am searching a python script for a string, but I would like to see not just the lines that contain the string, but also if that code is nested inside a function or method (or, optionally, a loop or conditional), I would like to see the lines where that function/method/etc. is 'declared' (not sure if that's the right terminology...)
I just mean, when I'm looking for STRING in a file like this:
class my_class(stuff):
some lines of code
line of code containing STRING
I'd like it to return:
class my_class(stuff):
line of code containing STRING
Instead of just:
line of code containing STRING
It doesn't have to be done with grep, specifically.