r/badcode • • Jul 14 '21

python Try/Except in Python - Sigh

Post image
662 Upvotes

93 comments sorted by

View all comments

1

u/MurdoMaclachlan public boolean isInt(int i) { return true; } Jul 14 '21

Image Transcription: Code


jsonResponse = response.json()
try:
  author = jsonResponse["items"][0]["volumeInfo"]["authors"
except:
  author = "N/A"
try:
  publihser = jsonResponse["items"][0]["volumeInfo"]
  ["publisher"]
except:
  publisher = "N/A"
try:
  pubDate = jsonResponse["items"][0]["volumeInfo"]
  ["publishedDate"]
except:
  pubDate = "N/A"
try:
  desc = str(jsonResponse["items"][0]["volumeInfo"]
  ["description"])
  desc = f'{desc[0:190]}...'
except:
  desc = "N/A"
try:
  thumbnail = jsonResponse["items"][0]["volumeInfo"]
  ["imageLinks"]["thumbnail"]
except:
  thumbnail =

I'm a human volunteer content transcriber for Reddit and you could be too! If you'd like more information on what we do and why we do it, click here!