dimanche 14 août 2022

How do I grab a random item from a JSON file in Python? [closed]

I am using a "quotes.json" file to store a list of quotes for a program and I need to select a random item from it. The list is structured like this:

[
  {
    "text": "Genius is one percent inspiration and ninety-nine percent perspiration.",
    "author": "Thomas Edison"
  },
  {
    "text": "You can observe a lot just by watching.",
    "author": "Yogi Berra"
  },
  {
    "text": "A house divided against itself cannot stand.",
    "author": "Abraham Lincoln"
  }
]

What is a simple way to grab a random text and author with a python script?




Aucun commentaire:

Enregistrer un commentaire