如何检测Python程序中的拼写错误 [英] How to detect typos in Python programs

查看:130
本文介绍了如何检测Python程序中的拼写错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


有没有办法在Python程序中检测拼写错误,之后确实需要运行它。假设我有这样的函数:


def server_closed_connection():

session.abost()


这里,abort()实际上是拼写错误。唯一一次我的程序

遵循这条路径是服务器断开它的

结束 - 这就像是在100个会话中一次。所以有时我会发布程序,人们开始使用它,然后有人

在发布4-5天之后报告这个错字(尽管它是

可以在用户端手动修复,或者我可以给一个补丁。


如何在开发时检测到这些类型的错误?

我有一个测试脚本可以让程序通过所有(大多数)可能的代码路径,这对我来说是不切实际的。
< br $> b $ b -Manish


-

Manish Jethani(gmx.net上的manish.j)

电话(工作)+ 91-80-51073488

Hi all,

Is there a way to detect typos in a Python program, before
actually having to run it. Let''s say I have a function like this:

def server_closed_connection():
session.abost()

Here, abort() is actually misspelt. The only time my program
follows this path is when the server disconnects from its
end--and that''s like once in 100 sessions. So sometimes I
release the program, people start using it, and then someone
reports this typo after 4-5 days of the release (though it''s
trivial to fix manually at the user''s end, or I can give a patch).

How can we detect these kinds of errors at development time?
It''s not practical for me to have a test script that can make
the program go through all (most) the possible code paths.

-Manish

--
Manish Jethani (manish.j at gmx.net)
phone (work) +91-80-51073488

推荐答案

Manish Jethani写道:
Manish Jethani wrote:

有没有实际上必须运行之前,在Python程序中检测拼写错误的方法。假设我有这样的函数:

def server_closed_connection():
session.abost()

这里,abort()实际上是拼写错误。我的程序唯一遵循此路径的时间是服务器从其结束时断开连接 - 这就像是100次会话中的一次。所以有时候我会发布程序,人们开始使用它,然后有人在发布4-5天之后报告这个错字(虽然它很容易在手动修复用户的结束,或者我可以给一个补丁。

我们怎样才能在开发时检测到这些错误?
对我来说测试是不切实际的可以使程序通过所有(大多数)可能的代码路径的脚本。

Is there a way to detect typos in a Python program, before
actually having to run it. Let''s say I have a function like this:

def server_closed_connection():
session.abost()

Here, abort() is actually misspelt. The only time my program
follows this path is when the server disconnects from its
end--and that''s like once in 100 sessions. So sometimes I
release the program, people start using it, and then someone
reports this typo after 4-5 days of the release (though it''s
trivial to fix manually at the user''s end, or I can give a patch).

How can we detect these kinds of errors at development time?
It''s not practical for me to have a test script that can make
the program go through all (most) the possible code paths.




你没有好的选择。为什么你说在软件发货之前对它进行实际测试是不切实际的?b $ b依靠用户测试软件更不可靠吗

认为它应该有用吗?


Python中的单元测试非常简单。我不能想到任何

理由不这样做是抓住像你这样的问题的最佳方式

如上所示。如果您拒绝:-),您可能会发现PyChecker

会有所帮助。我不确定它是否可以在上述情况下做任何事情

但是。


-Peter



You have no good alternative. Why do you say it''s impractical
to actually test your software before it''s shipped? Isn''t it
more impractical to rely on your users to test the software,
thinking it should work?

Unit testing in Python is *really* easy. I can''t think of any
reason not to do it as the best way of catching problems like you
show above. If you resist :-), however, you might find PyChecker
will help. I''m not sure if it can do anything in the above case
yet, however.

-Peter


Manish Jethaniaécrit:
Manish Jethani a écrit :
大家好,

有没有办法在Python程序中检测拼写错误,之后才真正需要运行它。
Hi all,

Is there a way to detect typos in a Python program, before
actually having to run it.




你可能想看一下pylint( http://www.logilab.org/pylint/


-

Alexandre Fayolle

LOGILAB,巴黎(法国)。
http:// www。 logilab.com http://www.logilab.fr http://www.logilab.org
$ b $bDéveloppementlogigielavancé - Intelligence Artificielle - 编队



You may want to give a look at pylint (http://www.logilab.org/pylint/)

--
Alexandre Fayolle
LOGILAB, Paris (France).
http://www.logilab.com http://www.logilab.fr http://www.logilab.org
Développement logiciel avancé - Intelligence Artificielle - Formations


Manish Jethani< ma ****** @ gmx.net>在消息新闻中写道:< ZP ************ @ news.oracle.com> ...
Manish Jethani <ma******@gmx.net> wrote in message news:<ZP************@news.oracle.com>...
大家好,

是有一种方法可以在实际运行它之前检测Python程序中的拼写错误。假设我有这样的函数:

def server_closed_connection():
session.abost()

这里,abort()实际上是拼写错误。我的程序唯一遵循此路径的时间是服务器从其结束时断开连接 - 这就像是100次会话中的一次。所以有时候我会发布程序,人们开始使用它,然后有人在发布4-5天之后报告这个错字(虽然它很容易在手动修复用户的结束,或者我可以给一个补丁。

我们怎样才能在开发时检测到这些错误?
对我来说测试是不切实际的可以使程序通过所有(大多数)可能的代码路径的脚本。

-Manish
Hi all,

Is there a way to detect typos in a Python program, before
actually having to run it. Let''s say I have a function like this:

def server_closed_connection():
session.abost()

Here, abort() is actually misspelt. The only time my program
follows this path is when the server disconnects from its
end--and that''s like once in 100 sessions. So sometimes I
release the program, people start using it, and then someone
reports this typo after 4-5 days of the release (though it''s
trivial to fix manually at the user''s end, or I can give a patch).

How can we detect these kinds of errors at development time?
It''s not practical for me to have a test script that can make
the program go through all (most) the possible code paths.

-Manish



这是关于我厌恶的解释语言 -
缺少编译时错误和警告。使用python,你可以

总是打开与解释器的交互式会话和''import

< filename>'',但这只会捕获语法错误。


对于未引用的变量和未定义的名称(错别字,因为

你喜欢很好地把它;-),我们用来测试我们的程序
代码:

http://pychecker.sourceforge。 net /


看看。不可否认,它输出的信息可能是压倒性的。花一些时间来检查它的行为和

选项。您最终可能会做的是通过修改源代码来定制其输出,或者通过

grep / awk / sed / python运行它来定制它的输出。但是,它绝对是一个起点

点。

-AJ


This is one of the things about interpreted languages that I detest-
lack of compile-time errors and warnings. With python, you can
always open an interactive session with the interpreter and ''import
<filename>'', but that only catches syntax errors.

For things like unreferenced variables and undefined names (typos, as
you like to nicely put it ;-), theres a program we use for testing our
code:

http://pychecker.sourceforge.net/

Have a look. Admittedly, the information it outputs can be
overwhelming. Take some time to just examine its behaviors and
options. What you''ll probably end up doing is customizing its output,
either by modifying the source, or running it through
grep/awk/sed/python afterwards. But, it''s definitely a starting
point.
-AJ


这篇关于如何检测Python程序中的拼写错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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