Write Pythonic Code Like a Seasoned Developer Transcripts
Chapter: Style guidance from PEP 8
Lecture: Who decides what is Pythonic?
0:01 Are you ready to start looking at some Pythonic examples and writing some code?
0:04 I sure am, we are going to start by focusing on PEP 8.
0:07 And some of the very basic structured ways
0:10 in which you are supposed to write Python code,
0:12 and then we'll quickly move beyond that
0:15 to more the patterns and techniques
0:17 that we are going to talk about for the rest of class.
0:19 So one of the first questions about this idiomatic Python code, this Pythonic code,
0:25 is "Who decides what counts as Pythonic and what doesn't?"
0:28 The way one person writes code may very well be different
0:32 than the way another person likes to write code,
0:34 and this is one of the reasons that exactly,
0:37 specifically stating what is Pythonic code and what does it look like is a challenge,
0:41 but there is a couple of areas where we might take inspiration
0:43 and pull together some sources and find some consensus.
0:47 One of them is just the community.
0:49 We can look at blogs, Stack Overflow,
0:51 things like that and see what people are saying
0:54 and what they agree or disagree upon.
0:56 So, here is a question that asked what is Pythonic code
0:59 and there is some examples given.
1:01 Another area that people take inspiration from
1:04 is something called The Zen of Python,
1:06 and if you want to look at The Zen of Python, this is by Tim Peters
1:09 you can just type import this inside of the REPL
1:11 in any version of Python and you'll get this,
1:13 and it's things like "beautiful is better than ugly,
1:16 flat is better than nested, errors should never pass silently";
1:19 again, this is not super concrete
1:22 but it does give some sort of structure about what is important and what isn't.
1:26 We also have PEP 8, Python Enhancement Proposal 8,
1:30 one of the very first official updates to the Python language
1:34 was this thing called PEP 8 which is a style guide for Python.
1:38 Mostly this talks about the actual structure of your code,
1:41 like "you should use spaces, not tabs", those types of things,
1:44 but it also has some guidance on patterns as well.
1:47 We'll look at the few of the recommendations from PEP 8
1:50 before we move on to the more design/pattern/style recommendations.