Effective PyCharm (2021 edition) Transcripts
Chapter: The Editor
Lecture: Formatting and code cleanup

Login or purchase this course to watch this video and the rest of the course contents.
0:00 As we were working through our programs,
0:01 you saw these little squiggly line up and one of the things that's really neat about
0:06 the python ecosystem is we have codified rules for basic formatting.
0:12 It doesn't talk about everything you should do.
0:14 But the basic stuff like how much space should be between functions and how should you
0:19 have spaces between the parameters and the commas that separate them and all that.
0:23 And this called pep 8. Python Enhancement Proposal eight.
0:27 It's one of the early ones.
0:29 PyCharm knows about this of course and it enforces these rules.
0:33 For example, here change email is supposed to have two blank lines between the function
0:37 above it find user by email.
0:40 Well, it would be nice if not only telling us about the problems if as
0:44 much as possible. PyCharm will just fix it and guess what it will
0:49 just reformat the code and you can even see here it says reformat the file
0:53 option shift, enter boom. Off it goes.
0:58 And then you can see it's actually added those two spaces and fixed it.
1:01 So you can do command+Alt+l or ctrl+alt+l depending on your key map.
1:06 Now there are times where it won't automatically fix it will tell you about pep8 violations
1:11 but it won't fix it. So imagine change email didn't have the underscore and the
1:15 e of email is capitalized that also is a pep8 violation when you have these compound
1:21 words you're supposed to separate them with underscore in the function and variable names are supposed
1:27 to be lower case so that would come up with squiggles.
1:30 But control this command alt L this reformat the code would not fix it.
1:36 It wouldn't fix it because that would be a breaking change for anyone consuming this library
1:39 And this is a package.
1:41 You've uploaded to PyPI
1:43 And you just reformat the code to magically fix it.
1:46 You might have made a breaking change for everyone who's used it previously and that would
1:49 be not good. So sometimes it just warned you about pep8.
1:54 Other times like this where it has no actual effect in terms of how the code
1:58 works like spaces and so on,
2:00 it will just fix it for you automatically. Cleverly.