Anything like 'inspect.getsourceencoding()'?

Jeff Epler jepler at unpythonic.net
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 = re.search("coding[:=]\s*([-\w.]+)", line)
            if m:
                return m.group(1)
        return "ascii"
Based on MvL's followup, I don't know where (if anywhere) this should be
included in the standard library.

Jeff
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20041017/3c040449/attachment.sig>


More information about the Python-list mailing list