def pyvar(string):
    """Transform a string into a valid Python variable

    :param string: Input string
    :return: Python variable-compatible string
    """
    for ch in string:
        if ch.isalpha() or ch.isdigit():
            pass
        else:
            string = string.replace(ch, '_')
    return string
