Modern Python Projects Transcripts
Chapter: Writing code
Lecture: PEP8 and PEP257
0:00 The best place to learn the fundamental rules on how to write your Python code is a document called pep 8, pep stands for Python enhancement proposal,
0:10 and it's a document published on Python website, that introduces some changes to the Python language
0:15 specification. All the new features that came to Python, where once proposed as a pep document,
0:21 and when they got accepted, they became a part of Python. One of those Python enhancement proposals, Number 8, is the Style Guide for Python code.
0:31 It was written by Guido von Rose, um, with the help of some other C Python core developers.
0:36 It's a long document specifying all the aspects of writing Python code. For example, it tells you how many spaces you should use,
0:43 what's the maximum line length, how to solve your import statements and so on. For each of those rules, you can also see some examples of good and bad
0:52 code. In addition to Pep 8, we also have pep257. This document explains how to write the docstrings.
1:01 So, the documentation for your code, there are a few simple rules that need to remember One set of rules is for docstrings that can fit in one line,
1:11 and another set of rules is for docstrings that will take multiple lines. For example, the one line Docstrings should start and end with triple quotes.
1:20 The closing quote should be on the same line as the opening one, and so on. Even if this is the first time you hear about those documents
1:26 if you are using a code editor that offers you auto formatting,
1:31 you are probably already following those rules anyway because that's the standard in the Python community So, unless you have a very good excuse,
1:39 you should follow those rules. The only one common exception from those rules is the
1:44 line length. Pep 8 recommends that you should not exceed 79 characters per line. But as our screens get bigger and bigger,
1:51 I see that more and more projects move away from this limitation and increase the maximum length upto 120 characters and even more.