Re: print line number and source filename

2010-11-22 Thread Wei Sun
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 >

Re: print line number and source filename

2010-06-24 Thread Vinay Sajip
On Jun 24, 4:07 am, Peng Yu wrote: > %(module)s only print to "__init__". However, I need the fullname > a.b.__init__. I looked at the manual, but I don't see what format > string I should supply. Would you please let me know? > Did you look at this part of the documentation? http://docs.python.

Re: print line number and source filename

2010-06-24 Thread Stephen Hansen
On Wed, Jun 23, 2010 at 8:07 PM, Peng Yu wrote: > I tried to put the above code in a module. Say in a.b.__init__.py > > %(module)s only print to "__init__". However, I need the fullname > a.b.__init__. I looked at the manual, but I don't see what format > string I should supply. Would you please

Re: print line number and source filename

2010-06-23 Thread Peng Yu
On Tue, Jun 22, 2010 at 12:13 PM, Stephen Hansen wrote: > On 6/22/10 9:44 AM, Peng Yu wrote: >> 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 exampl

Re: print line number and source filename

2010-06-22 Thread Stephen Hansen
On 6/22/10 10:26 AM, Shashwat Anand wrote: > begin - > import logging > logging.basicConfig(level=logging.DEBUG,format="%(asctime)s" > "%(levelname)-5.5s [%(name)s %(module)s:%(funcName)s:%(lineno)d]" > "%(message)s") > > def run(): >x = 5 >logging.debug("X = %d" % x) > > run() >

Re: print line number and source filename

2010-06-22 Thread Shashwat Anand
begin - import logging logging.basicConfig(level=logging.DEBUG,format="%(asctime)s" "%(levelname)-5.5s [%(name)s %(module)s:%(funcName)s:%(lineno)d]" "%(message)s") def run(): x = 5 logging.debug("X = %d" % x) run() - end - You can probably use string default concatenation

Re: print line number and source filename

2010-06-22 Thread Shashwat Anand
you can use __file__ On Tue, Jun 22, 2010 at 10:14 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 inspec

Re: print line number and source filename

2010-06-22 Thread Stephen Hansen
On 6/22/10 9:44 AM, Peng Yu wrote: > 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 numb

Re: print line number and source filename

2010-06-22 Thread Shashwat Anand
22:26:51 l0nwlf-MBP:~/Desktop$ cat test.py print __file__ 22:26:55 l0nwlf-MBP:~/Desktop$ python test.py test.py On Tue, Jun 22, 2010 at 10:26 PM, Shashwat Anand wrote: > you can use __file__ > > > On Tue, Jun 22, 2010 at 10:14 PM, Peng Yu wrote: > >> I want to print filename and line number fo

print line number and source filename

2010-06-22 Thread Peng Yu
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