is there a way to get the encoding of python file

Robert Kern robert.kern at
Sun Sep 12 19:28:32 CEST 2010

On 9/12/10 4:14 AM, Stef Mientki wrote:
>   hello,
> Is it possible to get the encoding of a python file from the first source line,
> (if there's any),
> after importing it ( with '__import__' )
> # -*- coding: windows-1252 -*-

The regular expression used to match the encoding declaration is given here:

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

More information about the Python-list mailing list