def is_python_script(filename):
    if filename.lower().endswith('.py'):
        return True

    if not os.path.isfile(filename):
        return False

    try:
        with open(filename, 'rb') as fp:
            if fp.read(2) != b'#!':
                return False
            return re.match(r'.*python', str_(fp.readline()))
    except IOError:
        pass

    return False
Checks a file to see if it's a python script of some sort.
dataset/ETHPy150Open tweekmonster/moult/moult/utils.py/is_python_script