12) Modules and Automation Lesson

Introduction: Python Automation

3 min to complete · By Martin Breuss

One of the fun reasons to learn about programming is that you can make your life a little easier as soon as you know a bit about it. Computers are good at automation, and your lines of code are the instructions that they need to know what to do.

Task Automation

In this section, you'll learn how you can interact with the file system on your computer by writing Python code. Your task is to clean up the mess on your Desktop:

Way too many screenshots on a Desktop

Someone has been taking way too many screenshots on your computer without ever cleaning them up! You have to weed through these files and move all the screenshots into a separate folder. Your aim is a clean Desktop:

Clean Desktop with CodingNomads logo as background image

But you won't do this manually by moving files over into a new folder. Instead, you'll write a Python script in which you'll use the built-in pathlib module to:

  • Find the files
  • Select only the ones that are screenshots
  • Create a new folder
  • Move the screenshots there

As a challenge, you'll even get the chance to rename the files, so you can give them a more descriptive name than just Screenshot-date.png.

Ready to start using Python for task automation? In an upcoming lesson, you'll even learn about how to import code someone else wrote and use it in your own script.

Summary: Introduction to Python Automation

  • Automation is when your program automatically completes a task that you were manually doing before
  • Task automation can save people a lot of time
  • Python is a great language for task automation