Anything like 'inspect.getsourceencoding()'?

"Martin v. Löwis" martin at v.loewis.de
Sun Oct 17 18:56:02 CEST 2004


Jeff Epler wrote:
> Is there a convenient way to find the encoding of a source file?  I
> thought maybe this would be in the inspect module, but I didn't see it
> there.  Just as nice would be a way to get the file as a unicode string,
> I suppose.

No. inspect operates on the byte-code/internal representation level, and
at that level, there is no notion of source encoding. The source
encoding information gets lost during compilation (as it is no longer
needed).

Somebody proposed preserving it in __[en]coding__, but that hasn't been
implemented.

Regards,
Martin



More information about the Python-list mailing list