Automate everyday tasks with Python
Small scripts that save time: files and folders, CSV and JSON, dates, text clean-up and regular expressions.
Many people learn Python to stop doing the same boring task by hand. This course shows the standard-library tools for that: working with files and folders, reading and writing CSV and JSON, dates and times, cleaning text and finding patterns with regular expressions. Every lesson ends with a small script you could use for real.
- 1What automation is and how to plan a scriptLearn which everyday jobs a Python script can do for you and how to plan one: input, steps, output and a safe dry run first.10 min
- 2Paths with pathlibBuild file and folder paths with pathlib.Path, take them apart with name, stem and suffix, check that they exist and create folders.14 min
- 3Listing and finding filesList what is in a folder with iterdir(), find files by pattern with glob() and rglob(), and count files by type, always in a fixed order.14 min
- 4Rename, copy, move and organise filesRename files with pathlib, copy and move them with shutil, avoid overwriting by accident, and sort a folder into sub-folders by type.16 min
- 5Read and write text files safelyRead and write text files with the right encoding, process them line by line, append to logs and save files without losing data on a crash.14 min
- 6CSV files with the csv moduleRead and write CSV files with csv.reader, DictReader and DictWriter, handle commas inside fields and semicolon files, and total a column.16 min
- 7JSON files and settingsTurn Python data into JSON and back with json.dumps, loads, dump and load, pretty-print it, and keep a script's settings in a JSON file.14 min
- 8Dates and timesWork with dates in scripts: build them with datetime, add days with timedelta, format and parse them with strftime and strptime.16 min
- 9Clean up messy textTidy text that people typed or programs exported: strip spaces, fix case, replace characters, compare names safely and remove accents.14 min
- 10Regular expressions, part 1Find patterns in text with Python's re module: search, findall, character classes, repetition and groups that pull out the parts you need.16 min
- 11Regular expressions, part 2Replace text with re.sub, compile patterns with flags, and solve real jobs: hide e-mail addresses, tidy phone numbers and convert dates.16 min
- 12Reports and text templatesTurn numbers into readable reports: format with f-strings, fill templates with str.format and string.Template, wrap text and draw tables.14 min
- 13Command-line scriptsTurn a script into a real command-line tool: read options with sys.argv and argparse, add a dry-run switch and log what happens.16 min
- 14Project: tidy my Downloads folderBuild a complete automation script: sort a messy Downloads folder into sub-folders by file type, avoid overwriting, and write a CSV report.25 min