我想要做的是有一個字典即是這樣我可以使用一個值作爲另一個字典的關鍵嗎?
((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()
然而,這是我的輸出:
任何幫助嗎?
嘿,我看了一下網站,並在我的代碼中運行它。我遇到了一些錯誤,將編輯我的文章 –