DEV Community

Mister Kay
Mister Kay

Posted on

Laziness Made Me Build a Python Tool That Generates Entire Project Structures

It’s funny how laziness is what got me into Python.

Not ambition. Not some grand plan to become a software engineer. Just pure laziness.

Repetitive tasks drain my brain. The kind where you keep doing the same thing over and over again. Creating folders. Creating files. Setting up project structures. It’s not hard work — it’s just annoyingly repetitive.

And one day I thought:

“Why not just write something that does it for me?”

That single thought is what eventually led me to build a Python tool that turns a simple text tree into a full project structure on disk.

The Real Origin Story

I’m a self-taught developer, and honestly AI played a big role in accelerating my learning.

But I noticed something interesting about AI: it’s extremely smart and extremely dumb at the same time. It can generate entire architectures in seconds, but it still needs your logic to make things actually work.

Around my fourth month of learning Python, I started building Telegram bots using Aiogram. Telegram was actually what pulled me into programming in the first place.

But every time I started a new bot project, I kept creating the same folders: src, handlers, data, utils, config, logs. And I kept doing this every single day. Open VS Code, create folder, create file, repeat. Over and over again.

If you’re building a large project, that process becomes incredibly tedious.

Eventually I thought: “What if I could describe the structure once and let Python create everything for me?”

The Idea: A Tree That Becomes a Project

The idea was simple. Instead of manually creating folders, I would write a tree structure in a text file, something like this:

project/
 src/
  main.py
 handlers/
  start.py
 data/
  database.db

Then Python would read the text and recreate that structure on disk automatically.

The script just needed to read the text file, understand the hierarchy, detect folders versus files, and create them in the correct order. Simple in theory. But the fun part was building the logic.

Step 1 — Handling Invalid File Names

Different operating systems have invalid characters for file names. So the first thing I wrote was a function to sanitize names.

Windows, for example, absolutely hates certain characters. If your script tries to create a folder like data:backup, it will fail. So the function simply replaces illegal characters with underscores. Small detail, but essential.

Step 2 — Parsing the Tree Structure

The heart of the script is the parser. It reads the tree and converts it into something Python can understand. Internally, it produces a list with each path, whether it’s a directory, and optional comments.

The tricky part was figuring out how deep a folder is in the tree.

Step 3 — Detecting Folder Depth

The trick is indentation. Each level in the tree is represented by four spaces. For example:

project/
 src/
  main.py

That means: project is at depth 0, src at depth 1, and main.py at depth 2.

Once we know the depth, we can reconstruct the full path.

Step 4 — Tracking Folder Hierarchy with a Stack

To rebuild the full path, I used a stack. Whenever we enter a folder, we push it to the stack. Then if we go back up the tree, we pop items from the stack. This ensures the current path always matches the correct hierarchy.

Step 5 — Previewing the Tree Before Creation

Before actually creating files, I added a preview mode. It prints the structure with folders and files so you can confirm everything is correct before writing to disk.

Step 6 — Creating the Files and Folders

Finally, the script builds the structure. Folders are created using the operating system’s folder creation methods, and files are created with simple write operations. If the tree includes a comment, the script even writes that comment inside the file automatically.

The Lazy Developer Evolution

At this point the script worked. But there was still a problem. Every time I wanted to run it, I had to open VS Code, navigate to the helpers folder, open a terminal, and run the script manually. That’s four steps. And remember — this project was born from laziness. Four steps is unacceptable.

The Next Upgrade: Turning It Into a .BAT Tool

So I took it one step further. I created a .bat file so I could run the script instantly from my desktop. Double-click. Boom. The project structure appears. No VS Code. No terminal. No navigation. Just click and generate.

At that moment the tool finally became what I originally wanted: a tiny utility that eliminates repetitive project setup.

A Thought About AI and Learning

While building this, I started thinking about something. Developers in the early 2000s didn’t have AI. They had Stack Overflow, documentation, and trial and error. Honestly, I respect those developers a lot. Without AI assistance, learning programming must have been a completely different battle.

Where I Am Now

I’m still a beginner developer. But building tools like this makes programming incredibly exciting. You start with something small, then it evolves, and suddenly you’re building tools that save you hours of work.

And now I’m already thinking: what am I going to build next?

Final Thought

Sometimes the best programming projects don’t start from ambition. They start from laziness. Because laziness forces you to ask the most powerful question in software: “Can I automate this?”

Top comments (0)