# Python Helpers for String/Unicode Encoding, Decoding and Printing

DevFeed: [Python Helpers for String/Unicode Encoding, Decoding and Printing](<https://devfeed.tech/articles/python-helpers-for-string-unicode-encoding-decoding-and-printing-31831.md>)

Original publisher: [Read original article](<https://www.metachris.dev/2015/11/python-tools-for-string-unicode-encoding-decoding-printing/>)

Author: Chris Hager

Published: 2015-11-23T00:00:00Z

Content type: tutorial

Language: en

Sources: [Chris Hager](<https://devfeed.tech/sources/chris-hager.md>)

Topics: [Python](<https://devfeed.tech/topics/python.md>), [Code](<https://devfeed.tech/topics/code.md>), [pdf](<https://devfeed.tech/topics/pdf.md>), [console](<https://devfeed.tech/topics/console.md>), [Windows](<https://devfeed.tech/topics/windows.md>)

Tags: [console](<https://devfeed.tech/tags/console.md>), [decoding](<https://devfeed.tech/tags/decoding.md>), [encoding](<https://devfeed.tech/tags/encoding.md>), [pdf](<https://devfeed.tech/tags/pdf.md>), [python](<https://devfeed.tech/tags/python.md>), [string](<https://devfeed.tech/tags/string.md>), [windows](<https://devfeed.tech/tags/windows.md>)

## AI overview

This tutorial presents two public-domain Python helpers: make_compat_str decodes bytes or strings into Unicode, while print_to_console prints Unicode safely across terminals and output encodings. The helpers are used in PDFx.

## Source excerpt

String encoding and decoding as well as encoding detection can be a headache, more so in Python 2 than in Python 3. Here are two little helpers which are used in PDFx, the PDF metadata and reference extractor: make_compat_str - decode any kind of bytes/str into an unicode object print_to_console - print (unicode) strings to any kind of console (even windows with cp437, etc.) All of this code is in the public domain via The Unlicense.