quandl / quandl-python

MIT License
1.38k stars 338 forks source link

if/elif/else could be replaced by a dict #39

Closed femtotrader closed 8 years ago

femtotrader commented 9 years ago

Hello,

I'm reading you code...

if I where you I won't write in https://github.com/quandl/quandl-python/blob/feature-AP-243/v3-client/quandl/connection.py

if code_letter == 'L':
    klass = LimitExceededError
elif code_letter == 'M':
    klass = InternalServerError
elif code_letter == 'A':
    klass = AuthenticationError
elif code_letter == 'P':
    klass = ForbiddenError
elif code_letter == 'S':
    klass = InvalidRequestError
elif code_letter == 'C':
    klass = NotFoundError
elif code_letter == 'X':
    klass = ServiceUnavailableError
else:
    klass = QuandlError

but

d_klass = {
    'L': LimitExceededError,
    'M': InternalServerError,
    'A': AuthenticationError,
    'P': ForbiddenError,
    'S': InvalidRequestError,
    'C': NotFoundError,
    'X': ServiceUnavailableError
}
klass_other = QuandlError
try:
    klass = d_klass[code_letter]
except KeyError:
    klass = QuandlError

Kind regards

mbasset commented 8 years ago

Hi femtotrader. Thanks for the suggestions. We will take this into consideration in our upcoming release. :)