Check out the inspect module:
inspect.stack()
will return the stack information.
Inside a function, inspect.stack()[1]
will return your caller's stack. From there, you can get more information about the caller's function name, module, etc.
See the docs for details:
http://docs.python.org/library/inspect.html
Also, Doug Hellmann has a nice writeup of the inspect module in his PyMOTW series:
http://pymotw.com/2/inspect/index.html#module-inspect
EDIT: Here's some code which does what you want, I think:
import inspect
def info(msg):
frm = inspect.stack()[1]
mod = inspect.getmodule(frm[0])
print '[%s] %s' % (mod.__name__, msg)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…