On this page
  1. shutil.chown
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

shutil.chown

Up: shutil | Next: shutil.copy
Rel: shutil.copy, shutil.copy2, shutil.copyfile, shutil.copyfileobj
Ref: docs.python.org — shutil.chown
Tags: #public #python3 #stdlib #shutil


Import

import shutil
from shutil import chown

Signature & Overview

shutil.chown(path, user=None, group=None, *, dir_fd=None, follow_symlinks=True)

Change owner user and group of the given path.

Usage

import os
from pathlib import Path
import shutil
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    p = Path(tmp) / "owned.txt"
    p.write_text("ok", encoding="utf-8")
    if hasattr(os, "getuid"):
        shutil.chown(p, user=os.getuid(), group=os.getgid())

Gotchas

REPL Inspect

from shutil import chown
help(chown)

Linked from

Related notes