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