errors with json.loads
Bill
BILL_NOSPAM at whoknows.net
Wed Sep 20 19:04:01 EDT 2017
john polo wrote:
> Greetings,
>
> I am using IPython 6.1.0 with Python 3.6.2 on a Windows 7 machine. I
> am not a programmer. I am using a book called Python Data Analytics to
> try to learn some of Python. I am at a section for reading and writing
> JSON data. The example JSON file is:
>
>
> Listing 5-13. books.json
> [{"writer": "Mark Ross",
> "nationality": "USA",
> "books": [
> {"title": "XML Cookbook", "price": 23.56},
> {"title": "Python Fundamentals", "price": 50.70},
> {"title": "The NumPy library", "price": 12.30}
> ]
> },
> {"writer": "Barbara Bracket",
> "nationality": "UK",
> "books": [
> {"title": "Java Enterprise", "price": 28.60},
> {"title": "HTML5", "price": 31.35},
> {"title": "Python for Dummies", "price": 28.00}
> ]
> }]
>
> and the example code for reading the file is:
>
> >>> file = open('books.json','r')
> >>> text = file.read()
> >>> text = json.loads(text)
Hmm... are you sure you want "text" on the left hand side. I'm not sure
whether this is okay or not. It looks suspicious (but, like I said, I'm
a Python newbie).
More information about the Python-list
mailing list