Python for AI Automation — Starter Lesson
Free Software starter lesson · 15 minutes · Beginner
Watch the Python Automation video.
Automate a file inventory
You will use Python to list CSV files and write a summary report. The script reads filenames only and writes a new report. Use a practice folder with no confidential files.
Set up your practice folder
Install Python 3 if needed. Create a folder named practice beside your script and put two empty files inside it named sales.csv and returns.csv, plus a file named notes.txt.
Write and run the script
from pathlib import Path
folder = Path(__file__).resolve().parent / "practice"
if not folder.is_dir():
raise SystemExit("Create the practice folder first.")
files = sorted(path.name for path in folder.glob("*.csv") if path.is_file())
report = folder.parent / "inventory.txt"
report.write_text(f"CSV files: {len(files)}\n" + "\n".join(files) + "\n", encoding="utf-8")
print(f"Wrote {report.name}")
Save the script as inventory.py and run python inventory.py or python3 inventory.py. Open inventory.txt. It should report two files in alphabetical order. The notes.txt file should be absent.
Try it yourself
Add budget.csv, run the script again, and predict the count and order before opening the report. Then remove all practice CSVs and check that the count becomes zero. In a real AI workflow, this inventory can define which files are eligible for processing before anything is sent to a model.
Explore Software Courses · Watch Econoria Videos
Continue with the paid course
€120 for one software course or €180 for five. Paid enrolment is not open yet. View Econoria course offers.
Open Learning Progress to mark this lesson complete or resume later.