Title: Python's UTF-8 Default: Keep Your File I/O Portable – Real Python
Open Graph Title: Python's UTF-8 Default: Keep Your File I/O Portable – Real Python
Description: Learn about the Python 3.15 UTF-8 default: see what changes, try it out, and keep your file I/O portable across every platform.
Open Graph Description: Learn about the Python 3.15 UTF-8 default: see what changes, try it out, and keep your file I/O portable across every platform.
Mail addresses
?subject=Python article for you&body=Python's UTF-8 Default: Keep Your File I/O Portable on Real Python
https://realpython.com/python315-utf8-default/
Opengraph URL: https://realpython.com/python315-utf8-default/
X: @realpython
Domain: realpython.com
{
"@context": "http://schema.org",
"@type": "Article",
"headline": "Python's UTF-8 Default: Keep Your File I/O Portable",
"image": {
"@type": "ImageObject",
"url": "https://files.realpython.com/media/Python-3.15-Preview-UTF-8-by-Default_Watermarked.5bc9458d892f.jpg",
"width": 1920,
"height": 1080
},
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://realpython.com/python315-utf8-default/",
"lastReviewed": "2026-10-12",
"author": {
"@type": "Person",
"name": "Leodanis Pozo Ramos",
"image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
"url": "https://realpython.com/team/lpozoramos/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
"reviewedBy": [
{
"@type": "Person",
"name": "Aldren Santos",
"image": "https://realpython.com/cdn-cgi/image/width=500,height=500,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Aldren_Santos_Real_Python.6b0861d8b841.png",
"url": "https://realpython.com/team/asantos/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
{
"@type": "Person",
"name": "Brenda Weleschuk",
"image": "https://realpython.com/cdn-cgi/image/width=320,height=320,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/IMG_3324_1.50b309355fc1.jpg",
"url": "https://realpython.com/team/bweleschuk/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
{
"@type": "Person",
"name": "Bartosz Zaczy\u0144ski",
"image": "https://realpython.com/cdn-cgi/image/width=1694,height=1694,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/coders_lab_2109368.259b1599fbee.jpg",
"url": "https://realpython.com/team/bzaczynski/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
}
]
},
"datePublished": "2026-09-02T14:00:00+00:00",
"dateModified": "2026-10-12T08:15:36.693690+00:00",
"publisher": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": {
"@type": "ImageObject",
"url": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png",
"width": 512,
"height": 512
},
"description": "Real Python is a leading provider of online Python education and one of the largest language-specific online communities for software developers. It publishes high-quality learning resources, such as tutorials, books, and courses to an audience of millions of developers, data scientists, and machine learning engineers each month.",
"slogan": "Become a Python Expert",
"email": "info@realpython.com",
"sameAs": [
"https://github.com/realpython",
"https://www.youtube.com/realpython",
"https://twitter.com/realpython",
"https://x.com/realpython",
"https://www.linkedin.com/company/realpython-com/",
"https://www.facebook.com/learnrealpython",
"https://www.instagram.com/realpython",
"https://www.tiktok.com/@realpython.com"
]
},
"author": {
"@type": "Person",
"name": "Leodanis Pozo Ramos",
"image": "https://realpython.com/cdn-cgi/image/width=862,height=862,fit=crop,gravity=auto,format=auto/https://files.realpython.com/media/Perfil_final1.9f896bc212f6.jpg",
"url": "https://realpython.com/team/lpozoramos/",
"affiliation": {
"@type": "Organization",
"@id": "https://realpython.com/#organization",
"name": "Real Python",
"url": "https://realpython.com",
"logo": "https://realpython.com/static/real-python-logo-square-512.157ae6bf64ed.png"
}
},
"description": "Learn about the Python 3.15 UTF-8 default: see what changes, try it out, and keep your file I/O portable across every platform.",
"hasPart": {
"@type": "FAQPage",
"mainEntity": [
{
"@type": "Question",
"name": "Will Python 3.15 break my existing file-reading code?",
"acceptedAnswer": {
"@type": "Answer",
"text": "\u003cp\u003eOnly if it relied on the platform default to decode a non-UTF-8 file, which is common on Windows. Add an explicit encoding, and it behaves the same everywhere.\u003c/p\u003e"
}
},
{
"@type": "Question",
"name": "How do I keep Python\u2019s old locale-based encoding?",
"acceptedAnswer": {
"@type": "Answer",
"text": "\u003cp\u003eSet \u003ccode\u003ePYTHONUTF8=0\u003c/code\u003e (or \u003ccode\u003e-X utf8=0\u003c/code\u003e) for the whole process, or pass \u003ccode\u003eencoding=\"locale\"\u003c/code\u003e on individual calls.\u003c/p\u003e"
}
},
{
"@type": "Question",
"name": "How do I get the real locale encoding?",
"acceptedAnswer": {
"@type": "Answer",
"text": "\u003cp\u003eCall \u003ccode\u003elocale.getencoding()\u003c/code\u003e. It reports the locale encoding regardless of UTF-8 mode, whereas \u003ccode\u003elocale.getpreferredencoding(False)\u003c/code\u003e now returns \u003ccode\u003e\"utf-8\"\u003c/code\u003e under the new default.\u003c/p\u003e"
}
},
{
"@type": "Question",
"name": "How can I find every place my code depends on the default encoding?",
"acceptedAnswer": {
"@type": "Answer",
"text": "\u003cp\u003eRun with \u003ccode\u003e-X warn_default_encoding\u003c/code\u003e (or \u003ccode\u003ePYTHONWARNDEFAULTENCODING=1\u003c/code\u003e) to emit an \u003ccode\u003eEncodingWarning\u003c/code\u003e at each implicit-encoding call. This works on Python 3.10 and later.\u003c/p\u003e"
}
},
{
"@type": "Question",
"name": "What\u2019s the difference between passing UTF-8 and locale as the encoding?",
"acceptedAnswer": {
"@type": "Answer",
"text": "\u003cp\u003eWhen you pass \u003ccode\u003eencoding=\"utf-8\"\u003c/code\u003e, Python always decodes the file as \u003ca href=\"/ref/computer-science-glossary/utf-8/\" class=\"ref-link\"\u003eUTF\u0026#45;8\u003c/a\u003e, so you get the same result on every machine. In contrast, \u003ccode\u003eencoding=\"locale\"\u003c/code\u003e hands the decision to the locale encoding, which can differ from one machine to another. Reach for \u003ccode\u003e\"utf-8\"\u003c/code\u003e unless you specifically need to match the user\u0026rsquo;s system setting. The \u003ccode\u003e\"locale\"\u003c/code\u003e value is available on Python 3.10 and later.\u003c/p\u003e"
}
}
]
}
}
| author | Real Python |
| theme-color | #18354c |
| color-scheme | light dark |
| twitter:card | summary_large_image |
| twitter:image | https://files.realpython.com/media/Python-3.15-Preview-UTF-8-by-Default_Watermarked.5bc9458d892f.jpg |
| og:image | https://files.realpython.com/media/Python-3.15-Preview-UTF-8-by-Default_Watermarked.5bc9458d892f.jpg |
| twitter:creator | @realpython |
| og:type | article |
| og:site_name | Real Python |
| apple-mobile-web-app-title | Real Python |
Links:
Viewport: width=device-width, initial-scale=1, shrink-to-fit=no, viewport-fit=cover
Robots: max-image-preview:large