규도자 개발 블로그

파이썬의 이스터에그 본문

Python/Python

파이썬의 이스터에그

규도자 (gyudoza) 2022. 5. 16. 19:57

파이썬의 이스터에그

import this

를 써서 실행해보자.

그러면 이런 글들이 나온다.

The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!

 

파이썬 10계명(?)이라 보면 된다. PEP문서에도 https://peps.python.org/pep-0020/ 이렇게 나와있는데 일종의 파이썬으로 개발하는 사람들이 지켜야할 철학이라고 보면 되겠다. 지금 세보니까 19계명이다.

 

궁금해서 zen이 뭔가 검색해보니 선불교(선종)를 Zen이라고 한다. 아마 이 선불교에서 "선"이라 칭하는 가치들을 교리로 삼고 지키는 것에 모티브를 따와서 Zen of Python이라는 느낌으로 간 게 아닌가 하는 추측이다.

 

예전에 FastAPI에 날린 PR중에 allow_rough_model이라는 기능을 넣은 적이 있었는데 (https://github.com/tiangolo/fastapi/pull/4758) 만약에 이게 필요한 시나리오라면 (response_model이랑 실제 response랑 다르다면) 또 하나의 스키마를 작성하는 게 맞다고 다른 리뷰어가 Zen of python을 언급한 적이 있었다. 난 파이썬을 배울 때 어디선가 문득 보고 흐릿하게 기억하던 것이었는데 PR을 계기로 다시 각인됐다고 해야하나. 뭐 아무튼 주기적으로 보면서 개발철학에 대해서 환기하는 방법도 좋을 것 같다.

 

 

 

Comments