How to stop myself overwriting Python functions when coding?

有些话、适合烂在心里 提交于 2019-12-04 06:35:55

Use a syntax-highlighting text editor that will highlight keywords in a different color from the rest of the code.

You should use Pylint. If you are using Eclipse + PyDev, you can configure it to run automatically within the IDE and highlight this issue (and many many others).

eat

Tools like PyChecker may be valuable for you. See also this SO discussion.

Accidentially using reserved names is a general problem; the general remedy is to use 'good' names for your own objects (in a broad sense). 'Good' here means names that tell you the relevant facts about the named object based on the context of the problem to solve.

For toy problems this may look like just to much effort, but why not train good naming even when you just write code to learn (features of) a language? So use your version of

list_with_duplicates = [ ... ]

pylint will find this error (among many others).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!