python拼写错误会导致程序终止_如何检测Python程序中的拼写错误

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 wrote: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.

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 Jethani a écrit :Hi all,

Is there a way to detect typos in a Python program, before

actually having to run it.

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 wrote in message news:...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

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

'', 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值