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

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

问题描述

我的代码中有几个错误。因此,我希望能够在开始时最小化它们,或者在代码执行之前看到尽可能多的错误。这是可能的,如果是这样,我该怎么做?

解决方案

如果你有语法问题,可以尝试具有语法高亮的编辑器。直到你得到一种语言的感觉,简单的错误就不会弹出你的。



最简单的调试方式只是插入一些打印语句。更高级(和可扩展)的方法是使用日志记录模块从std lib。



交互式解释器是使用python代码的好工具,而 IPython 对内置REPL(读评估打印循环)来说是一个很大的改进。



如果你真的想通过您的代码,python调试器称为 pdb ,可以从命令行,或嵌入到代码中。



如果您习惯于完全集成的IDE,我建议使用Eclipse与pydev,PyCharm有一个很好的商业提供,自动完成,快速访问文档,以及许多其他有趣功能的许多快捷方式。


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.

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.

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).

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.

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天全站免登陆