execfile error exception line number?

B

Brian Blais

Hello,

I'd like to do the following:

import sys
try:
execfile("somefile.py")
except:
s=sys.exc_info()
print "Error '%s' happened on line %d" % (s[1],s[2].tb_lineno)


(I'm going to replace the print later with a gui dialog)

how can I get the line number in "somefile.py" where the error occurs? When I do the
above, I get the line number in the script which calls execfile instead.


thanks,


Brian Blais
 
?

=?iso-8859-1?B?QW5kcuk=?=

Brian said:
Hello,

I'd like to do the following:

import sys
try:
execfile("somefile.py")
except:
s=sys.exc_info()
print "Error '%s' happened on line %d" % (s[1],s[2].tb_lineno)
How about this:
=== input: ====
try:
execfile("somefile.py")
except Exception, info:
print "Error '%s' happened on line %d" % (info[0], info[1][1])
==== output: ====
Error 'invalid syntax' happened on line 3
=== somefile.py is =====
print 3
print 3
prnt 5
print 6
=============


André
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top