Menu Close

How to set sys.stdout encoding in Python 3?

Sometimes, we want to set sys.stdout encoding in Python.

In this article, we’ll look at how to set sys.stdout encoding in Python.

How to set sys.stdout encoding in Python 3?

To set sys.stdout encoding in Python, we can call the sys.stdout.reconfigure method.

For instance, we write

sys.stdout.reconfigure(encoding='utf-8')

to call sys.stdout.reconfigure with the encoding argument set to 'utf-8'.

This will change the stdoud encoding to utf-8.

Conclusion

To set sys.stdout encoding in Python, we can call the sys.stdout.reconfigure method.

Posted in Python, Python Answers