Modern Python Projects Transcripts
Chapter: Writing code
0:00 Another popular category of tools that can help you, while you write code is called linters
0:04 Unlike the black formatter that we saw in the previous lesson.
0:08 Linters, don't modify your code,
0:11 but they will give you a real time feedback about your code.
0:15 The two most popular Linters for Python are pylint and flake 8.
0:19 Let me show you how they work.
0:21 For testing, I wrote another ugly piece of code.
0:24 I swear this is not how I usually write code,
0:26 as you can see. First,
0:28 I'm importing a non existing function that well, doesn't exist in this module.
0:34 Then I import os module, but I actually don't even use it.
0:37 Then I create a class, that looks OK, but has some additional white spaces here and
0:42 there, and it doesn't have empty lines between functions.
0:46 Then I have a function that it's supposed to create an instance of this class and
0:50 print my name. But as you can see,
0:53 first, I use a variable that it's not even defined.
0:56 And then I don't use this me variable.
0:58 But I use the python class instead. So this code won't even work, by default with
1:03 Only, The python extension installed.
1:05 We already have some feedback saying that this variable is undefined.
1:10 You can actually see the list of all problems.
1:13 Yeah, only one problem. And even if we change this unnamed variable to something
1:17 that actually exist, this code still won't work because this non existing function cant be
1:22 imported. And even if we remove this import,
1:26 the code will work. But it won't work as expected,
1:28 because I wanted to print my name.
1:31 But I made a mistake. And instead I will probably get none, let's actually run
1:35 to see it. Yeah, As you can see,
1:37 nothing was printed because me is not passed my function.
1:41 I could actually go here and replace person with me.
1:45 And it still doesn't work because it's not main.
1:49 It's a double underscore main (__main__).
1:51 And finally we get those results.
1:54 As you can see, one way to the debug
1:56 this code is to rerun it, and each time try to fix whatever error we have
1:59 But a lot of those errors can actually be spotted when you install a linter
2:03 So, let's install, pylint and flake 8 and see what they can tell us.