I have a mistake that I can't solve.. have you got an advice?
[root@leemi wwwroot]# python3 DateRead.py
Traceback (most recent call last):
File "DateRead.py", line 33, in <module>
data_ls = json.load(data_file)["Person"].values()
AttributeError: 'list' object has no attribute 'values'
Code created in VS.
import os
import datetime
import psycopg2
import inspect
import json
import io
from collections import OrderedDict
mtime = os.path.getmtime("data.json")
with io.open("saveDate.txt", "r", encoding="utf8") as date_read:
ttime = date_read.read()
if str(mtime) == ttime:
with io.open('data.json', "r", encoding="utf-8") as data_file:
data_ls = json.load(data_file)["Person"].values()
# datas1 = OrderedDict(sorted(data_ls["Person"].itemsc(), key=lambda t: t[0]))3
# print(datas1)
datas = list(data_ls)
# datas2 = [str(datas["PersonSex"]), str(datas["PersonAge"]), str(datas["PersonDate"])]
print(datas[0],datas[1],datas[2])
with io.open("saveDate.txt","w",encoding="utf-8") as date_save:
date_save.write("{0}".format(mtime))
print("INSERT INTO public.\"DbPerson\"(\"PersonSex\", \"PersonAge\", \"PersonDate\") VALUES ('{0}',{1},'{2}');".format(datas[0], datas[1], datas[2]))
VS has no errors. However, an error occurs at run time in Centos 7. As I'm a beginner of Python, I've searched for many things, but I can't solve them. Please help me.
Result
F 40 2020-05-01 8:10:00
INSERT INTO public."DbPerson"("PersonSex", "PersonAge", "PersonDate") VALUES ('F',40,'2020-05-01 8:10:00');