Reputation: 53
I'm learning python. And i learned every comment starts with a hash "#". So how can the python interpreter read this line?
# -*- coding: utf-8 -*-
and set the charset to utf-8 ? (I'm using Python 2.7.3) Thank you in advance.
Upvotes: 0
Views: 53
Reputation: 318508
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.
Upvotes: 1