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:01 In Python, it's great that we have pep 8, it tells us how to format our code, how to name our variables and so on. However, we don't always follow it
0:10 or more writing code, reorganizing code, sometimes we get it into a place where it doesn't quite line up.
0:16 So if we hover over say this change address thing there's actually a few problems. First of all, pep 8 says we expected two blank lines
0:24 from the find user by email function so it should have two more lines below; and according to our current conventions,
0:31 we really should have something like change (lowercase a) address this is very much like Javascript style or Java style of function naming
0:41 both for new email and for change address and it's not very Pythonic we should be using snake case after all. How do we fix this?
0:49 Well, if we just hit CMD ALT L or CTRL ALT L or whatever the hotkey is for reformat code as we saw before this can change,
0:59 but on Mac by default is CMD ALT L and I think CTRL alt L on the others it will reformat this and fix the pep 8 violations
1:07 so you notice that it actually went and it said okay we'll put those two lines there for you and if there was like other spaces or other minor things
1:14 they will all be automatically fixed. But a change address— well, if we're going to change address
1:19 that actually might break other code and other modules or heck if this is a package that somebody uploads to PyPi, and then someone else downloads it,
1:30 that could have like far ranging problems or knock on effect so it's not going to fix that automatically,
1:35 but the refactoring would let us fix it at least within our project right away, but it will just give us a warning no autofix.


Talk Python's Mastodon Michael Kennedy's Mastodon