This document discusses the Zen of Python philosophy and PEP 8 style guide for writing Python code. It begins by introducing the author and their background. It then explains how to view the Zen of Python principles by importing the "this" module. Several of the Zen principles are listed and explained. The document continues by covering PEP 8 guidelines for indentation, whitespace, comments and other stylistic choices. It provides examples of preferred versus non-preferred coding styles. It concludes by mentioning tools for linting and formatting Python code and provides additional resources for learning more.
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
Zen and the Art of Python
1. Zen and the Art of Python
Clayton Parker - Pythology 101
Zen and the Art of Python - Clayton Parker - Pythology 101
2. Who am I?
Director of Engineering at Six Feet Up
claytron on the internets
3. The Zen of Python
and
The Python Style Guide
(PEP8)
4. The Zen of Python
$ python -m this
>>> import this
5. The Zen of Python
$ python -m 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. Comments
# Comments start with a space after the comment symbol. Use complete
# sentences and proper grammar when writing comments. Comments should
# be in English unless you are certain the readers will *not* be
# English speaking.
# Long flowing text should be kept to under 72 columns like above.
x = 5 # Use inline comments sparingly.
11. Indentation
4 space indents
Tabs only if the prevailing style
Never mix tabs and spaces!
31. for item in items:
if some_check(item):
# do some magic
if another_check(item):
# more magic
operate_on(item)
32. for item in items:
if not some_check(item):
continue
if not another_check(item):
continue
# do some magic
# more magic
operate_on(item)
33. aws_region = None
for k,v in query_response.items():
if k == 'entry_list':
for i in v:
for k, v2 in i.items():
if k == 'name_value_list':
if isinstance(v2, dict):
for k2, v3 in v2.items():
if k2 == 'aws_region':
aws_region = v3['value']