Anything like 'inspect.getsourceencoding()'?

Robert Brewer fumanchu at amor.org
Sun Oct 17 15:29:34 EDT 2004


Just wrote:
> In article <mailman.5071.1097991055.5135.python-list at python.org>,
>  "Robert Brewer" <fumanchu at amor.org> wrote:
> 
> > Jeff Epler wrote:
> > > Is there a convenient way to find the encoding of a source file?
> > 
> > Short answer: no, you have to guess. But check out some 
> good guessing
> > algorithms at e.g. http://manatee.mojam.com/~skip/python/decodeh.py
> 
> You don't have to guess if the file has a
> 
> # -*- coding: encoding -*-
> 
> line. Such a line is required anyway, as of Python 2.3, if the source 
> file contains non-ascii chars.

Ah, thanks. I wasn't reading "source file" as "Python module".


Bob



More information about the Python-list mailing list