Anything like 'inspect.getsourceencoding()'?

Jeff Epler jepler at
Sun Oct 17 20:31:01 CEST 2004

Here's my implementation of getsourceencoding:
    def getsourceencoding(object):
        f = open(inspect.getabsfile(object), "r")
        for i in range(2):
            line = f.readline()
            m ="coding[:=]\s*([-\w.]+)", line)
            if m:
        return "ascii"
Based on MvL's followup, I don't know where (if anywhere) this should be
included in the standard library.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <>

More information about the Python-list mailing list