Last active
August 27, 2021 16:55
-
-
Save 1N0T/46703880c5cb73cfd333ddff5c8c84d5 to your computer and use it in GitHub Desktop.
(python) Determinamos el nombre de la función actual, así como desde donde ha sido llamada.
This file contains hidden or 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
def mi_funcion(): | |
import inspect | |
print(f"Ahora me encuentro en la función {inspect.stack()[0][3]}") | |
print(f"He sido llamado por {inspect.stack()[1][3]}") | |
def funcion_intermedia(): | |
mi_funcion() | |
print("Llamada desde otra función") | |
print("==========================") | |
funcion_intermedia() | |
print("\n\n") | |
print("Lamada desde módulo principal") | |
print("=============================") | |
mi_funcion() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment