mutapath.Path.renaming

Path.renaming(lock=True, timeout=1, method: Callable[[str, str], None] = <built-in function rename>)[source]

Create a renaming context for this immutable path. The external value is only changed if the renaming succeeds.

Parameters
  • timeout – the timeout in seconds how long the lock file should be acquired

  • lock – if the source file should be locked as long as this context is open

  • method – an alternative method that renames the path (e.g., os.renames)

Example

>>> with Path('/home/doe/folder/a.txt').renaming() as mut:
...     mut.stem = "b"
Path('/home/doe/folder/b.txt')