def is_valid_course_key(key):
 try:
  course_key = CourseKey.from_string(key)
 except InvalidKeyError:
  course_key = key
 return isinstance(course_key, CourseKey)

def is_valid_course_key ( key ) : try : course_key = CourseKey . from_string ( key ) except InvalidKeyError : course_key = key return isinstance ( course_key , CourseKey )
validates course key .