<p>I've had to do some introspection in python and it wasn't pretty:</p>

<pre><code>name = sys._getframe(1).f_code
name = "%s:%d %s()" %(os.path.split(name.co_filename)[1],name.co_firstlineno,name.co_name)
</code></pre>

<p>To get something like</p>

<pre><code>foo.py:22 bar() blah blah
</code></pre>

<p>In our debugging output.</p>

<p>I'd ideally like to prepend anything to stderr with this sort of information -- 
Is it possible to change the behaviour of print globally within python?</p>

[{'answer_id': 41574, 'author': 'Curt Hagenlocher', 'author_id': 533, 'author_profile': 'https://Stackoverflow.com/users/533', 'pm_score': 3, 'selected': True, 'text': '<p>A print statement does its IO through "sys.stdout.write" so you can override sys.stdout if you want to manipulate the print stream.</p>\n'}, {'answer_id': 41921, 'author': 'Pat Notz', 'author_id': 825, 'author_profile': 'https://Stackoverflow.com/users/825', 'pm_score': 1, 'selected': False, 'text': '<p>The python <a href="http://www.python.org/doc/current/lib/module-inspect.html" rel="nofollow noreferrer">inspect</a> module makes this a lot easier and cleaner. </p>\n'}]
['https://Stackoverflow.com/questions/41562', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4319/']