python debug小技巧&&工程能力的几点建议
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python debug小技巧&&工程能力的几点建议相关的知识,希望对你有一定的参考价值。
Debug小技巧:
转载请声明本文的引用出处:仰望大牛的小清新
1.初次编程时,在每一个if后面都写上else,这样,如果你的else原本是不应该运行的,那么就可以在else中输出此时的状态信息便于排查bug
2.不要嵌套太多的if(比如超过2层),因为嵌套多意味着需要来回查看不同层次的条件,尝试用一层if来做
3.像对待段落一样对待if-else,在它们开头和结尾加上空行,而把if-elif-else看作段落中的句子
4.if中的bool表达式应尽量简洁,如果态复杂,就用变量保存起来,并且给变量起个好名字
WARNING:Never be a slave to the rules in real life. For training purposes, you need
to follow these rules to make your mind strong, but in real life sometimes these rules
are just stupid. If you think a rule is stupid, try not using it.
关于调试和编程:
1.Make sure parts of your programs work as you work on them. Do not write massive files
of code before you try to run them. Code a little, run a little, fix a little.
关于工程能力:
One final word of advice: All programmers become paralyzed by irrational fear starting a new
large project. They procrastinate to avoid contronting this fear and end up not getting their pro-
gram working or even started. I do this. Everyone does this. The best way to avoid this is to make
a list of things you should do and then do them one at a time.
Just start doing it, do a small version, make it bigger, keep a list of things to do, and do them.
2.The best way to debug a program is to use print to print out the values of variables at
points in the program to see where they go wrong.
以上是关于python debug小技巧&&工程能力的几点建议的主要内容,如果未能解决你的问题,请参考以下文章
Visual Studio 调试技巧[Command Window & Immediate Window ](Tips)