python - "TypeError: list indices must be integers, not str": yaml.load_all? -


i want parse yaml file having following data structure:

    version: 1     txncode: mpt     messageid: "ffh-18544-1388620740-795905"     recommendations:       - {reqsegflightref: [[1,2]],totalpriceref: 1,priceinforef: 1}      - {reqsegflightref: [[3,4,2]],totalpriceref: 2,priceinforef: 2}      - {reqsegflightref: [[5,4,2]],totalpriceref: 3,priceinforef: 3}     flights:       - {opcarrier: sn,mktcarrier: sn,flightnb: 2902,dptdate: "0109",dpttime:     "09:30",arrtime: "11:05",dptairport: vie,arrairport: bru}      - {opcarrier: sn,mktcarrier: sn,flightnb: 243,dptdate: "0109",dpttime: "12:15",arrtime: "17:00",dptairport: bru,arrairport: fna}      - {opcarrier: os,mktcarrier: lh,flightnb: 6325,dptdate: "0109",dpttime: "06:30",arrtime: "07:35",dptairport: vie,arrairport: muc}     prices:       - {totalprice: 1574.14,baseamount: 1368.00,totaltaxe: 206.14,totalsurcharge: 0.00,totalfee: 0.00}      - {totalprice: 1633.57,baseamount: 1368.00,totaltaxe: 265.57,totalsurcharge: 0.00,totalfee: 0.00}      - {totalprice: 1636.57,baseamount: 1368.00,totaltaxe: 268.57,totalsurcharge: 0.00,totalfee: 0.00}   lfsdetails: |     priceinfos:       - {faresref: [1,2],price: {total: 1574.14},amount: {total: 1368.00},taxes:  {total: 206.14},surcharges: {total: 0.00},fees: {total: 0.00}}      - {faresref: [3,4,2],price: {total: 1633.57},amount: {total: 1368.00},taxes: {total: 265.57},surcharges: {total: 0.00},fees: {total: 0.00}}      - {faresref: [3,4,2],price: {total: 1636.57},amount: {total: 1368.00},taxes: {total: 268.57},surcharges: {total: 0.00},fees: {total: 0.00}}     listcabinrequested: []     fareinfo:       - {rbd: m,farebasis: bffowat,ptc: adt,breakpointid: n,availability: 9,cabin: w,faretype: ob}      - {rbd: b,farebasis: bffowat,ptc: adt,breakpointid: y,availability: 9,cabin: w,faretype: ob}      - {rbd: b,farebasis: bffowat,ptc: adt,breakpointid: n,availability: 9,cabin: m,faretype: ob}     currency: eur 

i have following code i'm having "typeerror: list indices must integers, not str" in line 20:

def yaml_load_all(istream,icodefilter=none):     ayamldoc in yaml.load_all(istream):         lfswrapper = lfswrapper(icodefilter)         lfsdetails = ayamldoc['lfsdetails'] #line 20         if lfsdetails not none:             ayamldoc['lfsdetails'] = yaml.load(lfsdetails)         lfswrapper.loaddict(ayamldoc)         if lfswrapper.isvalid():             yield lfswrapper 

(i'm calling method later istream set sys.stdin read data file).

i think i'm missing basic here regarding data structure or way yaml.load_all working.

what missing?

i presume using pyyaml.

load_all loading multiple yaml documents in single file, , returns list. have single document, maps python dict, should use load.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -