Effective PyCharm 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, you saw these little squiggly line up and one of the things that's really neat about
0:07 the Python ecosystem is we have codified rules for basic formatting. It doesn't talk about everything you should do.
0:15 But the basic stuff like how much space should be between functions and how should you
0:20 have spaces between the parameters and the commas that separate them and all that. And this called pep 8. Python Enhancement Proposal eight.
0:28 It's one of the early ones. PyCharm knows about this of course and it enforces these rules.
0:34 For example, here change email is supposed to have two blank lines between the function above it find user by email.
0:41 Well, it would be nice if not only telling us about the problems if as much as possible. PyCharm will just fix it and guess what it will
0:50 just reformat the code and you can even see here it says reformat the file option shift, enter boom. Off it goes.
0:59 And then you can see it's actually added those two spaces and fixed it. So you can do command+Alt+l or ctrl+alt+l depending on your key map.
1:07 Now there are times where it won't automatically fix it will tell you about pep8 violations
1:12 but it won't fix it. So imagine change email didn't have the underscore and the
1:16 e of email is capitalized that also is a pep8 violation when you have these compound
1:22 words you're supposed to separate them with underscore in the function and variable names are supposed
1:28 to be lower case so that would come up with squiggles. But control this command alt L this reformat the code would not fix it.
1:37 It wouldn't fix it because that would be a breaking change for anyone consuming this library And this is a package. You've uploaded to PyPI
1:44 And you just reformat the code to magically fix it. You might have made a breaking change for everyone who's used it previously and that would
1:50 be not good. So sometimes it just warned you about pep8. Other times like this where it has no actual effect in terms of how the code
1:59 works like spaces and so on, it will just fix it for you automatically. Cleverly.


Talk Python's Mastodon Michael Kennedy's Mastodon