This article is mainly to share with you some Python programming habits, mainly in the way of code and we explain, hope to help everyone.
1. Write the program document (format, auto indent (vim setting line width and autoindent), note) as follows:
2, as far as possible to streamline the code:
Such as
Can be written as:
return element in Sub_list
3. The code should not be coupled with the data:
If try not to write OS.GETCWD () in the script to get the path of the current script, so that the path obtained is Python execution of the path of the bash, if the execution of the bash path changes will cause the program is not reproducible. Workaround: Pass the path as a python execution parameter (python filename.py script_path) or through Os.path.split (Os.path.realpath ("__file__")) [0], Such paths are not limited by the bash execution path. Of course, in general, the first direct route is the best way.