Python Forum
Need help in python scripting
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Need help in python scripting
#14
Json file: -
{
"id": 1,
"name": "Auto",
"architecture": {
"axe": [
"j",
"y",
"r",
"t",
"x"
],
"p": [
"Vir",
"M"
]
},
"LL": [
{
"id": 10,
"name": "A",
"xx": "D",
"bb": "aa",
"yy": "S"
]
}
}

python script used:-
import sys
import json
import csv
reload(sys)
sys.setdefaultencoding('utf8')
with open('a.json','r') as f:
        json_data=json.load(f,strict=False)
with open('a.csv','w') as outfile:
        csv_write=csv.writer(outfile,quoting=csv.QUOTE_ALL)
        csv_write.writerow(["id","xx"])
        for json_d in json_data["a"]:
                row_array = []
                try:
                        row_array.append(json_d["Id"])
                except KeyError:
                        row_array.append('')
                try:
                        row_array.append(json_d["LL"][0]["xx"])
                except (KeyError,TypeError):
                        row_array.append('')
                except TypeError:
                        row_array.append('')
                csv_write.writerow(row_array)
outfile.close()
i am getting error -IndexError: list index out of range on command -row_array.append(json_d["LL"][0]["xx"])
Reply


Messages In This Thread
Need help in python scripting - by rajrishi990 - Nov-25-2019, 02:13 PM
RE: Need help in python scripting - by ichabod801 - Nov-25-2019, 03:44 PM
RE: Need help in python scripting - by rajrishi990 - Nov-26-2019, 06:25 AM
RE: Need help in python scripting - by rajrishi990 - Nov-26-2019, 09:35 AM
RE: Need help in python scripting - by DeaD_EyE - Nov-26-2019, 11:24 AM
RE: Need help in python scripting - by rajrishi990 - Nov-26-2019, 12:32 PM
RE: Need help in python scripting - by DeaD_EyE - Nov-26-2019, 12:51 PM
RE: Need help in python scripting - by rajrishi990 - Nov-26-2019, 01:24 PM
RE: Need help in python scripting - by DeaD_EyE - Nov-26-2019, 03:23 PM
RE: Need help in python scripting - by rajrishi990 - Nov-26-2019, 03:46 PM
RE: Need help in python scripting - by rajrishi990 - Nov-27-2019, 03:51 AM
RE: Need help in python scripting - by rajrishi990 - Nov-27-2019, 07:12 AM
RE: Need help in python scripting - by buran - Nov-27-2019, 09:03 AM
RE: Need help in python scripting - by rajrishi990 - Nov-27-2019, 09:12 AM
RE: Need help in python scripting - by buran - Nov-27-2019, 09:27 AM
RE: Need help in python scripting - by rajrishi990 - Nov-27-2019, 09:28 AM
RE: Need help in python scripting - by DeaD_EyE - Nov-27-2019, 11:56 AM
RE: Need help in python scripting - by buran - Nov-27-2019, 12:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Blender scripting the_jl_zone 0 491 Jul-10-2023, 08:48 PM
Last Post: the_jl_zone
  Python Scripting Environment jpotter0 1 1,784 Nov-19-2022, 03:07 PM
Last Post: snippsat
  Scripting: Multiple Votes With a Single Click or Button Ovidiu 0 1,411 Jul-07-2020, 10:51 AM
Last Post: Ovidiu
  Abaqus Python Scripting..Key error maddy 0 4,831 May-19-2018, 08:05 AM
Last Post: maddy
  Network scripting bsoth 1 2,688 Feb-06-2018, 01:41 AM
Last Post: wavic

Forum Jump:

User Panel Messages

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