Refactoring Your Code
00:00 So after cleaning up the code comments, I want to do a bit of refactoring. I’ve noticed that having the file extensions hidden down towards the end of the script makes it a bit hard to know which image files is the script actually looking for.
, ".svg", and then the script would also move
.svg files. And having this tuple up here at the beginning of the script makes it a little easier to maybe understand what’s happening here and also to maintain it. All right.
So I’m going to say
FULL_PATH, copy this, and I have to paste it here, and there’s another use. Looks good. I think I caught all of the mentions of
practice_dir there and replaced them with
FULL_PATH. If you’re using a more advanced text editor, there’s good refactoring features that make this easier.
and I might actually get rid of this
DIRECTORY after my final test and move it all into just the
FULL_PATH constant. But let’s talk about this in a bit. For now, I think I’m good with this refactoring.
I like having added this
IMAGE_EXTENSIONS here and also renamed
practice_dir to just the general path, and that gives you a bit more flexibility in changing your script to maybe also work for other file paths later on.
Now to also keep the script docstring up to date, I’m going to add a short note about the
IMAGE_EXTENSIONS constant. You can define which image files to move by changing the `IMAGE_EXTENSIONS` constant.
Become a Member to join the conversation.