TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

An underrated feature in Python 3

112 pointsby ionelmalmost 11 years ago

7 comments

erikbalmost 11 years ago
What I don't understand about Python is why it's not printing the str() of the variables in the corresponding lines of the traceback. About 95% of all debugging starts with adding prints or logging messages before the lines mentioned in the traceback. Or am I doing something wrong here (since 5 years...)?
评论 #8136852 未加载
评论 #8136831 未加载
评论 #8136847 未加载
评论 #8136924 未加载
评论 #8137437 未加载
评论 #8136829 未加载
评论 #8136826 未加载
评论 #8136862 未加载
the_mitsuhikoalmost 11 years ago
To be honest. As cool as this feature is in the 1% of cases where I wanted it, so annoying is it in 99% of all other cases. Tracebacks on Python 3 became a lot more complex because very often exceptions are intentionally swallowed to be reraised differently and they just mess up the traceback now.<p>For instance any custom collection that acts as a decorator will now generate very large tracebacks.<p>I would have much preferred if the reraising with old traceback would have been a feature you can enable per site where you raise.
评论 #8136863 未加载
aturekalmost 11 years ago
I don&#x27;t understand Python exceptions that well. But it&#x27;s great to have the pattern of maintaining the stack trace when re-raising an exception. Thanks OP!<p>(In case anyone missed it)<p><pre><code> except foo.FooException as e: raise BarException, BarException(e), sys.exc_info()[2]</code></pre>
whalesaladalmost 11 years ago
Had the pleasure of working with the author (Ionel) a few years back on some Django projects. Always love reading his Python posts. Really inspiring developer.
viraptoralmost 11 years ago
Actually passing the exception is not required. Even if &quot;e&quot; is not an argument to BarException, the behaviour is the same.
dragonwriteralmost 11 years ago
Why is the current title (&quot;An underrated feature in Python 3&quot;) neither the original source title (&quot;The most underrated feature in Python 3&quot;) or a title more descriptive of the content (e.g., &quot;Exception chaining in Python 3&quot;).<p>If we&#x27;re going to get title changes, can we at least get <i>useful</i> title changes?
评论 #8137708 未加载
raldialmost 11 years ago
Can a moderator de-hype the title, please?<p>[Edit: thanks!]
评论 #8137636 未加载
评论 #8136933 未加载