def get_topic_name(path_to_db): print("\nCurrent list of topics:\n") topics = DbHandler.list_topics(path_to_db) for topic in topics: print(topic) print( "\nPlease insert the topic name, or a new one, case insensitive. It cannot contain spaces." ) while True: topic_name = input("Topic name: ") if " " in topic_name: print("It cannot contain spaces.") else: if not os.path.exists("scripts/" + topic_name.lower()): print("Directory scripts/" + topic_name.lower() + " not found.") else: for topic in topics: if topic_name.lower() == topic.lower(): return topic return topic_name