(text, filename='<string>')
Is this string a valid Python script?
Is this string a valid Python script?
Is this string a valid Python script?
def is_python(text, filename='<string>'):
    "Is this string a valid Python script?"
    try:
        compile(text, filename, 'exec')
    except (SyntaxError, TypeError):
        return False
    else:
        return True
def is_python ( text , filename = '<string>' ) : try : compile ( text , filename , 'exec' ) except ( SyntaxError , TypeError ) : return False else : return True