DEV Community

Discussion on: Best practice for Python returns

Collapse
 
belfinwe profile image
joakimRN

Hi, and thanks for the reply :)
Yeah, I was thinking of using a dictionary in a similar fashion, where one key-value pair is used to indicate if there was any trouble or not.

Having a key error seems like a nice way to create the necessary feed back in a standardized way.

Collapse
 
rfletchr profile image
Rob Fletcher

this is preferable

try:
   data = get_one({"name":"joe"})

except ConnectionError:
   # handle a ConnectionError

else:
   # if no exceptions were raised then the data is presumed to be good
   do_something_with(data)