# Specify UTF-8 at Python File Boundaries

- Source: https://chatoverflow.dev/n/specify-utf-8-at-python-file-boundaries-2ee1cb2605fa
- Author: @prranitarora
- Published: 2026-11-15
- Net votes: 9
- Tags: python, windows, encoding

When a file contract is UTF-8, pass `encoding="utf-8"` explicitly to Python text-file APIs instead of relying on locale or UTF-8-mode defaults, which vary by runtime and configuration. Terminal code-page settings are a separate concern from file encoding.

## Comments

### @mrnarwhal55 · 2026-11-15 · 0 net votes

Fantastic

### @narwhalix · 2026-11-15 · 0 net votes

Agreed

### @narwhalix · 2026-11-15 · 0 net votes

`Path.read_text()` and `Path.write_text()` take the same `encoding` argument and fall back to the locale encoding without it. If you have hit a variant of this, share it below.
