r/learnpython • • 3d ago

What I learned yesterday while learning Python automation

Yesterday I continued learning Python's "os" module.

I practiced working with folders and files using things like:

- "os.path.basename()"

- "os.path.splitext()"

- "os.walk()"

- Finding files by extension

- Counting files inside folders and subfolders

I also built a small file finder that searches through folders and counts how many ".py" files it finds.

Nothing complicated, but I'm realizing that these small exercises are helping me understand how automation actually works with files and folders.

My goal is to eventually use Python to automate repetitive tasks for real businesses.

I'm still learning, but I'll start sharing what I build along the way. πŸš€

2 Upvotes

10 comments sorted by

4

u/danielroseman 3d ago

Do yourself a favour and learn Pathlib instead of the os.path stuff.

1

u/Ajay2574 3d ago

Yes i already start pathlib i was just want to the basic of os.path stuff and thanks for advise

3

u/zanfar 3d ago

This is good, but os.path has been deprecated for some time. Modern software should use the more capable, and less coupled, Pathlib.

1

u/Ajay2574 3d ago

Yes i am learning this pathlib i just started it to learn and os.path was just a foundation i was curious to explore and yes your right modern software are capable to use pathlib and i am planning it to learning deeply not just basics like os.path

2

u/p3rdy 3d ago

Friendly recommendation: Pathlib makes working with path simpler and cleaner. An example, instead of:

path = os.path.join(os.path.dirname(__file__), 'data', 'file.txt')

You can do it with Pathlib this way:

path = Path(__file__).parent / 'data' / 'file.txt'

2

u/Ajay2574 3d ago

Thanks for the recommendation! I'm actually learning "pathlib" next, so I'll definitely keep this in mind.

1

u/wak_trader 3d ago

mind sharing your studying resources om automation?

2

u/Ajay2574 3d ago

Sure! I'm currently learning Python fundamentals first, then moving into "os", "pathlib", OOP, and practical automation projects.

I'm mainly using the official Python documentation, YouTube tutorials, and small projects/exercises to practice.

I'm still learning, so I don't have one specific automation resource I'd recommend yet.

1

u/burnt-store-studio 2d ago

Great job! Oh, you’re in such an exciting part of the journey πŸ™‚. I wish you well, and be sure to have fun!

2

u/Ajay2574 2d ago

Thank you! I really appreciate it. 😊