我想做的是有一个像
((category1: subcategory1, sub2, sub3), (cat2: sub12, sub22...))
但是,我也希望子类别也有自己的值:
((subcat1: subitem1, subitem2), (subcat2: subitem12, subitem22)...)
我希望能够引用子项,使其连接到原始类别,而不仅仅是子类别。有没有办法做到这一点?
编辑:
import json
import win32com.client as win32
from glob import glob
import io
import locale
from collections import defaultdict
import pprint
#import re
#importing needed clients
raw_files = glob('*.xlsx')
x = locale.getpreferredencoding()
print x
ex = win32.gencache.EnsureDispatch('Excel.Application')
ex.Visible = False
oFile = open("rawsort.txt", "w+")
#oFile = io.open("rawsort.txt", "w+", encoding = "utf-8")#text dump
for f in raw_files:
ex.Workbooks.Open(f)
sheet = ex.ActiveWorkbook
#print sheet.Sheets("MRD").Cells(1,2).Value
wincs = sheet.Worksheets('MRD')
if sheet.Sheets("MRD").Cells(1, 3).Value== None:
wincs.Cells(1,3).Value = u'N/A'
if sheet.Sheets("MRD").Cells(1, 4).Value== None:
wincs.Cells(1,4).Value = u'N/A'
if sheet.Sheets("MRD").Cells(1, 5).Value== None:
wincs.Cells(1,5).Value = u'N/A'
if not wincs.Cells(1,2).Value == None:
category[sheet.Sheets('MRD').Cells(1,2).Value][wincs.Cells(1,3).Value][wincs.Cells(1,4).Value] = wincs.Cells(1,5).Value
# print listy
print sheet.Sheets('MRD').UsedRange.Rows.Count
for x in xrange(2, sheet.Sheets("MRD").UsedRange.Rows.Count+1):#for loop to print through paragraphs
if sheet.Sheets("MRD").Cells(x, 3).Value== None:
wincs.Cells(x,3).Value = u'N/A'
if sheet.Sheets("MRD").Cells(x, 4).Value== None:
wincs.Cells(x,4).Value = u'N/A'
if sheet.Sheets("MRD").Cells(x, 5).Value== None:
wincs.Cells(x,5).Value = u'N/A'
if not sheet.Sheets("MRD").Cells(x, 2).Value== None:
category[sheet.Sheets('MRD').Cells(x,2).Value][wincs.Cells(x,3).Value][wincs.Cells(x,4).Value] = wincs.Cells(x,5).Value
#oFile.write(unicode(listy))
oFile.write("\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\n")
oFile.close()
但是,这是我的输出:
有什么帮助吗?