is there a way to get the encoding of python file

Robert Kern robert.kern at gmail.com
Sun Sep 12 13:28:32 EDT 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:

http://docs.python.org/reference/lexical_analysis.html#encoding-declarations

-- 
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