On this page
  1. nturl2path
  2. Import
  3. Overview
  4. Quick Start
  5. Implementation Walkthrough
  6. 1. Portable Alternative via urllib.request
  7. Gotchas & Boundaries
  8. Common Functions

nturl2path

Prev: ntpath | Up: stdlib_module | Next: numbers
Rel: email, json, mailbox, mimetypes, base64
Ref: docs.python.org — nturl2path
Tags: #public #python3 #stdlib


Import

import nturl2path

Overview

Internal Windows helper module used by urllib.request to convert between local Windows paths (C:\path\file) and URL path components (///C:/path/file). Do not import nturl2path directly—use urllib.request.pathname2url(), urllib.request.url2pathname(), or pathlib.Path.as_uri() instead.

Quick Start

import nturl2path

url_part = nturl2path.pathname2url(r"C:\Users\Ada\report.txt")
assert url_part == "///C:/Users/Ada/report.txt"
assert nturl2path.url2pathname(url_part) == r"C:\Users\Ada\report.txt"

Implementation Walkthrough

1. Portable Alternative via urllib.request

For cross-platform code, call urllib.request.pathname2url() and urllib.request.url2pathname(), which automatically dispatch to nturl2path on Windows and standard percent-encoding on POSIX.

Gotchas & Boundaries

Common Functions

Linked from

Related notes