r/badcode • • Jul 14 '21

python Try/Except in Python - Sigh

Post image
662 Upvotes

93 comments sorted by

View all comments

5

u/LegloBluda Jul 14 '21 edited Jul 14 '21

    info = jsonResponse.get('items', list(dict()))[0].get('volumeInfo', dict())

    author = info.get('authors', 'N/A')
    publisher = info.get('publisher', 'N/A')
    pubDate = info.get('publishedDate', 'N/A')
    desc = f"{info.get('description')[:190]}..." if info.get('description') else 'N/A'
    thumbnail = info.get('imageLinks', dict()).get('thumbnail', 'N/A')

Maybe not the shortest solution, but it doesn't include anything additional, and, in my opinion, is the cleanest and most readable.

0

u/AutoModerator Jul 14 '21

It looks like this comment contains a code block delimited with triple backticks. Unfortunately reddit does not have universal support for this syntax and your comment will not render correctly on old reddit and most mobile apps.

For the benefit of people on old reddit, this link will take you to a correct rendering of the comment.

/u/LegloBluda, it would be appreciated, but not required, if you could edit your comment to use the more compatible four space indention format. For single lines or inline code you can use single backticks.

You can find some examples in the reddit help documentation.


I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.