0

私はパイソンを学んでいます。そして、すべてのコメントがハッシュ「#」で始まることを学びました。では、Python インタープリターはこの行をどのように読み取ることができるのでしょうか?

# -*- coding: utf-8 -*-

文字セットを utf-8 に設定しますか?(私は Python 2.7.3 を使用しています) よろしくお願いします。

4

1 に答える 1

1

Yes, it is a comment. But this does not mean that python doesn't see it. So it can obviously parse it, too.

What python actually does is using the regular expression coding[:=]\s*([-\w.]+) on the first two lines. Most likely this is done even before the actual python parser steps in.

See PEP-0263 for details.

于 2013-05-26T13:21:10.087 に答える