故意有错误的代码 (Python)

发布于 2024-09-13 19:08:13 字数 160 浏览 4 评论 0原文

这是一个奇怪的请求,但我正在寻找有错误的 Python 代码。我想了解有关错误和调试器的更多信息,并且需要一些有错误的代码来处理。不幸的是,我编写的所有代码都很短并且没有错误(到目前为止)。

最好不是 GUI 的东西(b/c 我刚刚开始学习它),但任何东西都很好。

提前致谢

This is a strange request but I'm looking for buggy Python code. I want to learn more about bugs and debuggers and I need some buggy code to work with. Unfortunately, all the code I've written is short and bug-free (so far).

Preferably it's not GUI stuff (b/c I'm just starting to learn it) but anything's good.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

顾冷 2024-09-20 19:08:13

不确定如何“故意”寻找有错误的源代码,但您可以查看主要 Python 项目(以及不太广泛的项目)的错误跟踪器,查找报告引用的错误并调试它们。这是一个双赢的局面。您赢得了调试技能,他们(希望)赢得了该错误的补丁:-)

Not sure how to scout "intentionally" for source code with bugs but you can look into the bug trackers of the main Python projects (and the less widespread ones, too), look for the bugs the reports refer to and debug them. It's a win-win situation. You win the skill to debug and they (hopefully) win a patch for the bug :-)

楠木可依 2024-09-20 19:08:13

调试的 70% 是关于在采取任何措施之前从异常报告中找到并找出错误,而 30% 是关于在修复错误时弄清楚如何不将纸牌城堡推倒。
如果你在代码中为你指出了这一点,或者只是给了你代码,但你被告知它有错误,那么你的处境比开始时更糟糕。

劳伦斯的评论在我看来是正确的,去寻找那些被跟踪和记录的东西,如果你想让这个练习有意义的话,你可以在一个项目中重新执行步骤,你有现实的约束和足够的代码库可以使用。
当你也必须弄清楚外星代码库时,这也是学习阅读的良好练习。

Debugging is 70% about finding and figuring out the bug from reports of anomalies before you can do anything about it, and 30% about figuring out how not to take the castle of cards down when fixing it.
If you have it pointed out in the code for you, or are just given code and you're told it's buggy, you're in a worse place than where you started.

Lawrence's comment is spot on IMO, go hunt down something that's been tracked and logged and you have rero steps for in a project where you have realistic constraints and enough codebase to work with if you want this exercise to have any meaning.
Will double as good exercise in learning to read too when you have to puzzle out an alien code base too.

樱花坊 2024-09-20 19:08:13

这是一个很好的例子,请找出错误;)

只是几年前让我困扰的一些代码。

methods = []                       
for i in range(10):                        
    methods.append(lambda x: x + i)        

print methods[0](10)                       

Here's a nice example, spot the bug ;)

Just a bit of code that bit me a couple of years ago.

methods = []                       
for i in range(10):                        
    methods.append(lambda x: x + i)        

print methods[0](10)                       
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文