Registry / devops / in-place

in-place

JSON →
library1.0.1pypypi✓ verified 82d ago

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-place
INSTALL
IMPORT
SIG · IN-PLACE
I
in-place
devopspythonv1.0.1
Install
1.5s avg
Import
20ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.022s · 17.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.019s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

InPlace
from in_place import InPlace
import in_place

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.

import in_place # Create a dummy file for demonstration with open('example.txt', 'w') as f: f.write('Line 1\n') f.write('Line 2 to be modified\n') f.write('Line 3\n') print('Original file content:') with open('example.txt', 'r') as f: print(f.read()) # Modify 'example.txt' in-place: change 'Line 2' to 'Modified Line 2' with in_place.InPlace('example.txt') as fp: for line in fp: if 'Line 2' in line: fp.write(line.replace('Line 2', 'Modified Line 2')) else: fp.write(line) print('\nModified file content:') with open('example.txt', 'r') as f: print(f.read())
Debug
Known issues
gotchaUnlike Python's standard `fileinput` module, `in-place` does not hijack `sys.stdout` for writing. Users coming from `fileinput` must explicitly call `fp.write()` to output modified lines, or `fp.write(line)` to preserve unchanged lines, otherwise content will be lost.
fix
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.
affects: All versions
gotchaWhen using `in_place.InPlace` with the `backup_ext` argument, providing an empty string for the extension will raise an error. The library explicitly prevents this to avoid ambiguity.
fix
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`.
affects: All versions
gotchaWhen working with binary files, remember to open `InPlace` in binary mode (`mode='b'`). Otherwise, the file will be opened in text mode (default `mode=None`), which can lead to unexpected encoding/decoding errors or corruption of non-textual data.
fix
For binary files, instantiate `InPlace` with `mode='b'`, e.g., `with in_place.InPlace('binary_file', mode='b') as fp:`.
affects: All versions
Upgrade
Version history
1.0.1latest on PyPI · released Dec 1, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
in-place — pip install in-place · libregistry