The `in-place` library provides an `InPlace` class for robust and convenient in-place editing of files. It handles temporary files, encoding, and error management, simplifying common tasks like filtering or transforming file contents without needing to manually manage temporary files or worry about data loss during unexpected interruptions. The current version is 1.0.1 and it is actively maintained with a focus on stability and compatibility.
pip install in-placeVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `in_place.InPlace` to read and write to a file, modifying its content in a transactional manner. It creates an example file, prints its original content, modifies a specific line using `in_place`, and then prints the updated content.
Always explicitly call `fp.write(line)` or `fp.write(modified_line)` within the `with in_place.InPlace(...) as fp:` block for every line you intend to keep or modify.
Provide a non-empty string for `backup_ext` (e.g., `.bak`, `~`) or use the `backup` argument to specify a complete backup file path if you need a backup. If no backup is desired, omit both `backup` and `backup_ext`.
For binary files, instantiate `InPlace` with `mode='b'`, e.g., `with in_place.InPlace('binary_file', mode='b') as fp:`.No dependency data recorded yet.