forked from mikeckennedy/write-pythonic-code-demos
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy path1.txt
More file actions
38 lines (38 loc) · 2.24 KB
/
Copy path1.txt
File metadata and controls
38 lines (38 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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.