Skip Stephen> I''ve just spent several very frustrating hours tracking down aStephen> bug in one of my programs. The problem was that I was writingStephen> text to a file, and when I was done I coded Stephen> f.close Stephen> when I should have been coding Stephen> f.close() Stephen> with the parentheses. Stephen> In any event, does anybody have any suggestions for how a coderStephen> could avoid making such a mistake, or detect it quickly? Pychecker would probably have warned about this. Given this four-line file: def bar():return 5 bar Pychecker reports: % pychecker foo.pyname: fooProcessing foo... Warnings... foo.py:4: Statement appears to have no effect Skip >斯蒂芬>我刚刚花了几个非常令人沮丧的时间追踪> Stephen> I''ve just spent several very frustrating hours tracking down a Stephen>我的一个程序中的错误。问题是我写的是斯蒂芬>文本到文件,当我完成后我编码 斯蒂芬> f.close 斯蒂芬>什么时候我应该编码 斯蒂芬> f.close() 斯蒂芬>括号。 斯蒂芬>在任何情况下,是否有人对编码器的方式有任何建议 Stephen>可以避免犯这样的错误,或者快速检测出来吗? Pychecker可能会对此发出警告。鉴于这个四行文件: Stephen> bug in one of my programs. The problem was that I was writing Stephen> text to a file, and when I was done I coded Stephen> f.close Stephen> when I should have been coding Stephen> f.close() Stephen> with the parentheses. Stephen> In any event, does anybody have any suggestions for how a coder Stephen> could avoid making such a mistake, or detect it quickly? Pychecker would probably have warned about this. Given this four-line file: 人们在使用Python进行编码时遇到的许多常见错误 编译器没有抓到。区分大小写的错误, 缩进等错误。 我认为PyChecker( 中提到.sf.net /target =_ blank> http://pychecker.sf.net/ ,并且应该与每个Python集成IDE。 键入任何内容之前,请键入import pychecker.checker There are numerous common mistakes people making when coding in Pythonthat the compiler doesn''t catch. Case-sensitive errors, errors inindenting, etc. I think PyChecker ( http://pychecker.sf.net/ ) should be mentioned inevery beginner tutorial, and should be integrated with every Python IDE.Before you type anything, type "import pychecker.checker" 这篇关于如何避免“f.close” (没有parens)错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-27 03:25