class CustomException(Exception): def __init__(self, value): self.parameter = value def __str__(self): return repr(self.parameter) def my_method(temp_dict): #this is the part I want to improve it looks messy if "key" not in temp_dict: raise CustomException("Message key is missing from dict") if "key1" not in temp_dict: raise CustomException("Message key1 is missing from dict") if "key2" not in temp_dict: raise CustomException("Message key2 is missing from dict") if "key3" not in temp_dict: raise CustomException("Message key3 is missing from dict") my_dict = {} my_dict["key"] = "test" my_dict["key1"] = "test" my_dict["key2"] = "test" my_method(my_dict)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question