R
R
Reality2018-07-02 21:02:39
Python
Reality, 2018-07-02 21:02:39

Does Python need to indicate encoding at the beginning of a file?

Please tell me how to format the file.
Some sources indicate that you need to write at the beginning:

# coding : utf-8
# PEP-8

On the github, someone writes only this:
# -*- coding: utf-8 -*-
And Google, for example, does not indicate either one or the other, and leaves only information about the license at the beginning of the file:
# Copyright (C) 2018 Google Inc.
# Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2018-07-02
Tester @Aoom

https://www.python.org/dev/peps/pep-0263/#examples
Worth mentioning if using weird IDEs/editors or python2 that can mess with utf-8

A
Alex F, 2018-07-03
@delvin-fil

If you want a different input / output from en_GB (for example, ru_RU), specify
# -*- coding: utf-8 -*-

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question