print line number and source filename
Wei Sun
sunwei415 at gmail.com
Mon Nov 22 11:23:05 EST 2010
Here is what you want for printing python source filename:
print __file__
> On Tuesday, June 22, 2010 12:44 PM Peng Yu 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 do not 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
> Submitted via EggHeadCafe
> Merging SharePoint List Data into Word Documents
> http://www.eggheadcafe.com/tutorials/aspnet/6054abc5-c5fb-4e86-a352-afd0e8c4a7c6/merging-sharepoint-list-data-into-word-documents.aspx
More information about the Python-list
mailing list