you can use __file__<br><br><div class="gmail_quote">On Tue, Jun 22, 2010 at 10:14 PM, Peng Yu <span dir="ltr"><<a href="mailto:pengyu.ut@gmail.com">pengyu.ut@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

I want to print filename and line number for debugging purpose. So far<br>
I only find how to print the line number but not how to print<br>
filename.<br>
<br>
import inspect<br>
print inspect.currentframe().f_lineno<br>
<br>
I found inspect.getsourcefile(), but I have to supply a class name to<br>
it. I have searched online, but I don't find how to print the source<br>
filename. Would you please let me know?<br>
<br>
Also, always importing the inspect module and getting the frame and<br>
accessing the lineno from the frame is not very convenient to type. Is<br>
there a shorter way to access the line number (for example, in C++ and<br>
perl, __LINE__ can be used to access line number, which is much more<br>
convenient than the way that I found in python).<br>
<br>
--<br>
Regards,<br>
Peng<br>
<font color="#888888">--<br>
<a href="http://mail.python.org/mailman/listinfo/python-list" target="_blank">http://mail.python.org/mailman/listinfo/python-list</a><br>
</font></blockquote></div><br>