擅长:python、mysql、java
<p>这个呢:</p>
<pre><code>try:
if x:
print 'before statement 1'
statement1
print 'before statement 2' #ecc. ecc.
statement2
statement3
elif y:
statement4
statement5
statement6
else:
raise
except:
statement7
</code></pre>
<p>这是简单的解决方法,但我建议使用调试器</p>
<p>或者更好,使用sys模块:D</p>
<pre><code>try:
if x:
print 'before statement 1'
statement1
print 'before statement 2' #ecc. ecc.
statement2
statement3
elif y:
statement4
statement5
statement6
else:
raise
except:
print sys.exc_traceback.tb_lineno
#this is the line number, but there are also other infos
</code></pre>