有什么好方法可以让我的 Python 代码第一次运行? [英] What are good ways to make my Python code run first time?

查看:25
本文介绍了有什么好方法可以让我的 Python 代码第一次运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码中有不少错误.因此,我希望能够在一开始就将它们最小化,或者在代码执行之前看到尽可能多的错误.这可能吗?如果可以,我该怎么做?

I'm getting quite a few errors in my code. Consequently, I would like to be able to minimize them at the outset or see as many errors as possible before code execution. Is this possible and if so, how can I do this?

推荐答案

如果您遇到语法问题,可以尝试使用具有语法突出显示功能的编辑器.除非你对一种语言有感觉,否则简单的错误不会突然出现在你身上.

If you're having problems with syntax, you could try an editor with syntax highlighting. Until you get the feel for a language, simple errors won't just pop out at you.

最简单的调试形式就是插入一些打印语句.一种更高级(和可扩展)的方法是使用 logging 来自标准库的模块.

The simplest form of debugging is just to insert some print statements. A more advanced (and extensible) way to do this would be to use the logging module from the std lib.

交互式解释器是处理 Python 代码的绝佳工具,IPython 是对内置解释器的巨大改进REPL(读取评估打印循环).

The interactive interpreter is a wonderful tool for working with python code, and IPython is a great improvement over the built-in REPL (Read Eval Print Loop).

如果你真的想单步调试你的代码,python 调试器被称为 pdb,可以从命令行调用,也可以嵌入到您的代码中.

If you actually want to step through your code, the python debugger is called pdb, which can be called from the command line, or embedded in your code.

如果您习惯使用完全集成的 IDE,我建议您将 Eclipse 与 pydev 结合使用,PyCharm 提供了出色的商业产品,包括自动完成、快速访问文档和众多快捷方式以及许多其他有趣的功能.

If you're used to a fully integrated IDE, I would recommend using Eclipse with pydev, and PyCharm has a great commercial offering, with autocomplete, quick access to docs, and numerous shortcuts, among many other interesting features.

这篇关于有什么好方法可以让我的 Python 代码第一次运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆