Reference library

Files & data

Read and write files safely; parse JSON, CSV, and common text formats.

1 match
Files & data easy

How to Transcode a File from Latin-1 to UTF-8 in Python

Read a latin1-encoded text file and rewrite it as UTF-8 using Python's pathlib and encoding parameters.

encoding utf8 latin1
Python
from pathlib import Path

def transcode_to_utf8(input_path, output_path):
    """Read a latin1-encoded file and write it as UTF-8."""
    source = Path(input_path)
    target = Path(output_path)
    
    with source.open(encoding='latin1') as infile:
        content = infile.read()
    
    with target.open('w', encod…
12 0 Open

Browse by section

Each section groups closely related Python snippets.

Files & data — Python code examples

What you will find here

This page collects files & data snippets — short, copy-ready Python you can paste into our free online IDE and run without installing anything. Each sample includes a plain-English explanation and the full source code.

Samples vs tutorials and challenges

Samples are quick reference — one concept per page. For step-by-step teaching, use our Python tutorials. To test yourself, try quizzes or coding challenges. Clean up style with the Python formatter.