On this page
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
- tuts/python3/stdlib_module/netrc Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ntpath Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/posix Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/stdlib_module Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/argparse Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/getopt Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/io Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/os Linked here; shared tags: #stdlib
- tuts/python3/stdlib_module/pathlib Linked here; shared tags: #stdlib