Python in bulk import json file

Python in the batch import file Json
work needs, Json named like this, so I wrote a batch import json way, and have the experience of subsequent supplementary message Ha

path='D:\data'
filelist = os.listdir(path)
fileIndex = []
for i in range(0 , len(filelist)):
   index = filelist[i].split(".")[0]
   fileIndex.append(int(index))
 #因为导入是
for j in range(1 , len(fileIndex)):
   for k in range(0 , len(fileIndex)-1):
       if(fileIndex[k]>fileIndex[k+1]):
           preIndex = fileIndex[k]
           preFile = filelist[k]
           fileIndex[k] = fileIndex[k+1]
           filelist[k] = filelist[k+1]
           fileIndex[k+1] = preIndex
           filelist[k+1] = preFile
data = []
labelpath = 'D:\data\\'
eachdata={}
for file in filelist:
   with open(labelpath + file, 'r') as f:
       temp = json.loads(f.read())
       eachdata[file] = temp

For reference predecessors, from this URL:
https://blog.csdn.net/weixin_44145300/article/details/90512158

Released two original articles · won praise 0 · Views 637

Guess you like

Origin blog.csdn.net/pt798633929/article/details/102795179