def is_python(text, filename='<string>'):
 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
is this string a valid python script? .