Python самоанализ - как проверить текущий модуль / строку вызова из функции

У меня есть функция:

# utils.py
def hello(name='World'):
    # Detect where I'm being called from.
    print('Hi, %s. You called this from %s at line # %d.' % (name, mod, lineno))
    # ``mod`` and ``lineno`` on previous line would have been set in real use.

Я импортирую эту функцию и запускаю ее в другом месте

# other.py (this comment at line # 138)
from utils import hello
hello('Johnny')  # From inside ``hello`` I want to be able to detect that this
# was called from other.py at line # 140
6
задан orokusaki 16 March 2011 в 14:13
поделиться