you can use __file__

On Tue, Jun 22, 2010 at 10:14 PM, Peng Yu <pengyu...@gmail.com> wrote:

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

Reply via email to