On this page
  1. posix
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Checking Platform Capabilities via os
  7. Gotchas & Boundaries
  8. Common Functions
  9. Classes & Objects
  10. Constants & Attributes

posix

Prev: poplib | Up: stdlib_module | Next: posixpath
Rel: os, io, time, argparse, getopt
Ref: docs.python.org — posix
Tags: #public #python3 #stdlib


Import

import posix

Overview

Low-level Unix/POSIX C-extension backing the os module on macOS, Linux, and BSD systems. Never import posix directly in portable code—always import os, which re-exports posix's functions alongside cross-platform wrappers like os.makedirs(), os.walk(), and os.environ.

Quick Start

import os

# os.name is "posix" on macOS/Linux/BSD; use os rather than importing posix directly
assert os.name in ("posix", "nt")
assert isinstance(os.getcwd(), str)

Implementation Walkthrough

1. Checking Platform Capabilities via os

If a script needs a POSIX-only syscall (such as os.fork, os.getuid, or os.statvfs), check hasattr(os, "getuid") or os.name == "posix" rather than importing posix directly so the module still imports cleanly on Windows.

Gotchas & Boundaries

Common Functions

Classes & Objects

Constants & Attributes

Linked from

Related notes