Using Python and Json and trying to replace sections -
i'm using python try , locate , change different parts of json file.
i have list 2 columns , want string in first column, find in json file , replace second column in list.
does have idea how this? been driving me mad.
for row in new_list: if json_str == new_list[row][0]: json_str.replace(new_list[row][0], new_list[row][1])
i tried using .replace() above says list indices must integers or slices, not list.
the way i've managed print off data works...
but not referencing anything, if has ideas, feel free lend hand, thanks.
import json # import json file , text file... # open('json file', 'r', encoding="utf8") jsondata: # data = json.load(jsondata) # jsondata.close() jsondata = {"employees":[ {"firstname":"a"}, {"firstname":"b"}, {"firstname":"c"} ]} # text_file = open('text file', 'r', encoding="utf8") # list = text_file.readlines() # jsonstring = str(data) # text file contains lots of data 'a|a', 'b|b, 'c|c' # column 1 lower , column 2 upper list = 'a|a, b|b, c|c' def print_all(): value in list: new_list = value.split("|") print("%s" % value.split("|")) # prints column 1 , 2 if new_list[0:] == 'some value': print(new_list[1]) # prints off 'replaced' value print_all()
edit comment, should able run... think
without more context it's hard sure, sounds though want use
for row in range(len(new_list)):
instead of
for row in new_list:
Comments
Post a Comment