TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

An underrated feature in Python 3

112 点作者 ionelm将近 11 年前

7 条评论

erikb将近 11 年前
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_mitsuhiko将近 11 年前
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 未加载
aturek将近 11 年前
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>
whalesalad将近 11 年前
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.
viraptor将近 11 年前
Actually passing the exception is not required. Even if &quot;e&quot; is not an argument to BarException, the behaviour is the same.
dragonwriter将近 11 年前
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 未加载
raldi将近 11 年前
Can a moderator de-hype the title, please?<p>[Edit: thanks!]
评论 #8137636 未加载
评论 #8136933 未加载