def _encode(ch):
    """
    Encode a single character.
    Anything not valid as Python identifier is encoded as '%N' where N
    is a decimal number of the character code point.
    """
    if ch.isalnum() or ch in '_':
        out = ch
    else:
        out = "%%%d" % ord(ch)
    return out