Modern Python Projects Transcripts
Chapter: Writing code
Lecture: PEP8 and PEP257

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