Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Hates me
#1
I am having the hardest time getting anything to work in python. I am not very familiar with it. I know c# fairly well. I am trying to open a json file and print a specific element from it. Nothing too difficult. Reguardless of what I do or which example I use I always get some error. I do not get it. I have vscode set up exactlty as the example. I copy and paste the code. I renamed my file to be the file name in the example. I keep getting an error about the json file needs to be a string. I get 2 different errors it depends on if I use json.load or json.loads. Any guidance would be appreciated. Below is the very simple code I found and link.

https://www.anycodings.com/1questions/53...ith-python
import json
from operator import itemgetter
import os


with open('file.json', 'r') as f:
  data = json.load(f)
  if data['inbound'] == 'true':
    print(data['url'])
this is an example of the json data
Output:
{ "date": "2021-06-14", "url": "https://liveupdate.symantec.com", "description": "Agent Installation Package", "inbound": false, "outbound": true }
Gribouillis write Aug-12-2022, 02:49 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Python Hates me - by quarinteen - Aug-12-2022, 02:08 PM
RE: Python Hates me - by rob101 - Aug-12-2022, 02:41 PM
RE: Python Hates me - by deanhystad - Aug-12-2022, 03:39 PM
RE: Python Hates me - by Gribouillis - Aug-12-2022, 09:47 PM
RE: Python Hates me - by Pedroski55 - Aug-13-2022, 04:38 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020