Last active
September 16, 2019 19:41
-
-
Save me2beats/8c491eda8c53447075ca194761451a93 to your computer and use it in GitHub Desktop.
Called_from_here behavior
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from inspect import currentframe, getouterframes | |
class CalledFromHereBhv: | |
def __init__(self): | |
curframe = currentframe() | |
self.called_from_module_fn,\ | |
self.called_from_start_line =\ | |
self._get_module_and_start_line(curframe) | |
def _get_module_and_start_line(self, curframe): | |
calframe = getouterframes(curframe, 2) | |
module, start_line = calframe[-1][1:3] | |
return (module, start_line) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from test import Test | |
Test() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from called_from_here_bhv import CalledFromHereBhv | |
class Test(CalledFromHereBhv): | |
def __init__(self, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
print (self.called_from_module_fn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment