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

os.chmod

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


Import

import os
from os import chmod

Signature & Overview

os.chmod(...)

Change the access permissions of a file.

Usage

import os
from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    p = Path(tmp) / "script.sh"
    p.write_text("#!/bin/sh\n", encoding="utf-8")
    os.chmod(p, 0o755)
    assert (p.stat().st_mode & 0o777) == 0o755

Gotchas

REPL Inspect

from os import chmod
help(chmod)

Linked from

Related notes