Maybe everyone has heard of “Python zen ”, It is from Python One of the core development members of Tim Peter Write , Become Python Programming and design guidelines .
Maybe you still know that python Input... In the interpreter import this You can see “Python zen ”, But why import this What about this sentence ？ Another little story in the middle ：
2001 In the autumn ,Foretec( A conference organization company ) Is preparing to hold the tenth International Python Conference(IPC 10,Pycon The forerunner of ),Foretec I plan to solicit a print for the meeting T The slogan on the T-shirt , In the end they came from Python The community received 500 Multiple submissions .
Foretec Invited Python The core development of Guido, Fred, Jeremy,Tim Peter,Barry Wait for the judges . The judges filtered out the contributions 130 There has been no progress since more than one , They didn't confirm the final slogan until the meeting was about to take place .
A few days before the meeting , It's time for the judges to have to make a decision . So the Tim Peter and Barry The two take turns judging , Half of them are eliminated each time, leaving half , Until at last there was only one .
Final ,“import this” Selected out , Everyone to "import this" Very satisfied with . But when you choose this one , They realized that they had to achieve it . After a brief discussion ,“import this” Of is set to output Tim Peter Written 《The Zen of Python》— There was no. ： One fruit, one melon
>>> import this The Zen of Python, by Tim Peters Beautiful is better than ugly. # 1. Beauty is better than ugliness （Python To write beautiful code as the goal ） Explicit is better than implicit. # 2. Clarity is better than obscurity （ Beautiful code should be clear , Naming specification , The style is similar ） Simple is better than complex. # 3. Simplicity is better than complexity （ Beautiful code should be concise , Don't have complex internal implementations ） Complex is better than complicated. # 4. Complexity is better than disorder （ If complexity is inevitable , That code can't have a difficult relationship , Keep the interface simple ） Flat is better than nested. # 5 Flat is better than nested （ Beautiful code should be flat , There can't be too much nesting ） Sparse is better than dense. # 6. Spacing is better than compactness （ Beautiful code with proper spacing , Don't expect a line of code to solve the problem ） Readability counts. # 7. Readability is very important （ Beautiful code is readable ） Special cases aren't special enough to break the rules. Although practicality beats purity. # 8. Even in the name of the practicality of special cases , And don't violate these rules （ These rules are supreme ） Errors should never pass silently. Unless explicitly silenced. # 9. Don't tolerate all mistakes , Unless you are sure you need to （ Capture exceptions accurately , Don't write except:pass Style code ）