On this page
  1. nt
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Guarding Windows-Specific os Features
  7. Gotchas & Boundaries

nt

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


Import

import nt

Overview

Low-level Windows C-extension backing the os module on Windows systems (the Windows counterpart to posix). Never import nt directly—import os instead so your code remains portable across operating systems.

Quick Start

import os

# Use os (which wraps nt on Windows and posix on Unix)
assert os.name in ("posix", "nt")
env_keys = list(os.environ.keys())
assert isinstance(env_keys, list)

Implementation Walkthrough

1. Guarding Windows-Specific os Features

When writing cross-platform tools that need Windows-only behaviors (like os.add_dll_directory()), gate them with sys.platform == "win32" or os.name == "nt" rather than importing nt.

Gotchas & Boundaries

Linked from

Related notes