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

os.chown

Prev: os.chmod | Up: os | Next: os.close
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.chown
Tags: #public #python3 #stdlib #os


Import

import os
from os import chown

Signature & Overview

os.chown(path, uid, gid, *, dir_fd=None, follow_symlinks=True)

Change the owner and group id of path to the numeric uid and gid.

Usage

import os
from pathlib import Path
import tempfile

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

Gotchas

REPL Inspect

from os import chown
help(chown)

Linked from

Related notes