Modern Python Projects Transcripts
Chapter: Course conclusion and review
Lecture: Static analysis
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
When you write Python code, there are two guidelines that you should keep in mind The most important one is Pep 8,
0:07
which is a style guide for Python code. It specifies how maney spaces to use for the indentation,
0:13
how to sort your import statements and things like that. There is also Pep257 that explains how to properly write the documentation strings for your
0:23
functions, classes and modules. The best way to implement those guidelines in your code is to use an automatic code formatter.
0:31
The most popular one is called black, and when you run it, it will automatically format your code according to the
0:38
PEP 8 rules. So you don't have to fix anything manually, and you can even configure your code editor to automatically format your code each time you
0:46
save it, which is pretty convenient. Another category of useful tools are linters,
0:52
like flake 8 or pylint. They will tell you when you make some mistakes in your code. For example, when you try to use a variable that it's not
1:00
defined, or when you import a module, but you don't use it. Of course they wont detect all kinds of bugs but
1:07
having a tool that will automatically monitor your code and try to spot at least some of the errors is very helpful.
1:15
You can extend Flake 8 with many useful plug ins, and if you want something more, you can use other static code analyzers like bandit,
1:22
prospector or sorcery. They all have different purpose, and they will report to different kinds of errors.
1:29
So if you want, you can use a few of them at the same time Last but not least when you want to take some Python code for a spin
1:36
you can use the default Python interpreter. But there are some other interpreters, like IPython BPython or PtPython that have much more features.
1:47
For example, they have syntax highlighting, auto completion, automatic indentation and so on. So if you spend a lot of time in the
1:55
Python terminal, using one of them will make your life much easier.