Articles from Sundeep Agarwal

"I help programmers learn tricky topics like Regular Expressions and CLI tools with understandable examples."

1 Article from Sundeep.

In-place file editing with fileinput module

This post shows how to edit one or more files in-place using the fileinput module.


Often, I have to make changes to existing files. For example, some software got updated, so I've to change version numbers. Or perhaps, I've changed the name of assets like input files, images, etc. If it's a single file, I'd likely just use my favorite text editor to open the file, make the changes and save it. If I have to edit multiple files, I'll write a Python script instead.

Continue reading