Я на самом деле пытаюсь сделать это динамически, но сейчас я просто надеялся получить статический пример, так как фрагменты кода, которые я нашел до сих пор, похоже, не работают для списков с таким глубоким вложением (или я Я неправильно понимаю, как применять синтаксис).
Со статической точки зрения я пытаюсь обновить подсписок 'runner' подсписка 'runner' (который затем является частью market_book и, в конечном счете, market_books), поэтому я подумал, что это сработает:
market_books[0].runners[0].x = 'test'
setattr(market_books[0].runners[0], 'y', 'test2')
print(market_books[0].runners[0].x, market_books[0].runners[0].y)
print(market_books[0].json())
Теперь первый отпечаток отображается точно так, как ожидалось (т. Е. Показывает тестовый тест2), однако, когда я пытаюсь напечатать следующий уровень, он не обновился, поэтому я предполагаю, что я на самом деле не обновляю его, а просто присвоение значения подсписку.
Полный набор данных выглядит следующим образом:
{"marketId":"1.130856098","totalAvailable":null,"isMarketDataDelayed":null,"lastMatchTime":null,"betDelay":0,"version":2576584033,"complete":true,"runnersVoidable":false,"totalMatched":null,"status":"OPEN","bspReconciled":false,"crossMatching":false,"inplay":false,"numberOfWinners":1,"numberOfRunners":10,"numberOfActiveRunners":8,"runners":[{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":2.8,"size":4},{"price":2.78,"size":20},{"price":2.76,"size":22}],"availableToLay":[{"price":2.82,"size":11.94},{"price":2.84,"size":9.45},{"price":2.86,"size":66.97}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832765},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":18.5,"size":2},{"price":18,"size":5},{"price":17.5,"size":2.7}],"availableToLay":[{"price":19.5,"size":2.44},{"price":20,"size":10},{"price":21,"size":2}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832767},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":12.5,"size":1.27},{"price":12,"size":14.96},{"price":11.5,"size":39.62}],"availableToLay":[{"price":15.5,"size":2},{"price":16,"size":15.18},{"price":16.5,"size":3.26}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832766},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":26,"size":1},{"price":25,"size":4},{"price":24,"size":2}],"availableToLay":[{"price":30,"size":2.22},{"price":32,"size":2},{"price":34,"size":2}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832769},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":15,"size":4},{"price":14.5,"size":3},{"price":14,"size":5.77}],"availableToLay":[{"price":17,"size":2},{"price":17.5,"size":2},{"price":18,"size":2}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832768},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":4.9,"size":51.43},{"price":4.8,"size":66.63},{"price":4.7,"size":43.31}],"availableToLay":[{"price":5,"size":108.94},{"price":5.1,"size":20},{"price":5.2,"size":2}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832771},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":20,"size":6},{"price":19.5,"size":2},{"price":19,"size":2}],"availableToLay":[{"price":22,"size":2},{"price":23,"size":2},{"price":24,"size":2}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":12832770},{"status":"ACTIVE","ex":{"tradedVolume":[],"availableToBack":[{"price":6.2,"size":8.04},{"price":6,"size":80.47},{"price":5.9,"size":2}],"availableToLay":[{"price":6.4,"size":69.24},{"price":6.6,"size":46},{"price":6.8,"size":102.33}]},"sp":{"nearPrice":null,"farPrice":null,"backStakeTaken":[],"layLiabilityTaken":[],"actualSP":null},"adjustmentFactor":null,"removalDate":null,"lastPriceTraded":null,"handicap":0,"totalMatched":null,"selectionId":10064909}],"publishTime":1552066850090,"priceLadderDefinition":{"type":"CLASSIC"},"keyLineDescription":null,"marketDefinition":{"bspMarket":false,"turnInPlayEnabled":false,"persistenceEnabled":false,"marketBaseRate":5,"eventId":"28180290","eventTypeId":"2378961","numberOfWinners":1,"bettingType":"ODDS","marketType":"NONSPORT","marketTime":"2019-03-29T00:00:00.000Z","suspendTime":"2019-03-29T00:00:00.000Z","bspReconciled":false,"complete":true,"inPlay":false,"crossMatching":false,"runnersVoidable":false,"numberOfActiveRunners":8,"betDelay":0,"status":"OPEN","runners":[{"status":"ACTIVE","sortPriority":1,"id":10064909},{"status":"ACTIVE","sortPriority":2,"id":12832765},{"status":"ACTIVE","sortPriority":3,"id":12832766},{"status":"ACTIVE","sortPriority":4,"id":12832767},{"status":"ACTIVE","sortPriority":5,"id":12832768},{"status":"ACTIVE","sortPriority":6,"id":12832770},{"status":"ACTIVE","sortPriority":7,"id":12832769},{"status":"ACTIVE","sortPriority":8,"id":12832771},{"status":"LOSER","sortPriority":9,"id":10317013},{"status":"LOSER","sortPriority":10,"id":10317010}],"regulators":["MR_INT"],"countryCode":"GB","discountAllowed":true,"timezone":"Europe\/London","openDate":"2019-03-29T00:00:00.000Z","version":2576584033,"priceLadderDefinition":{"type":"CLASSIC"}}}
У меня есть динамический код, который я использую (например, пара циклов for, однако, чтобы избежать путаницы, если кто-то будет достаточно любезен, чтобы помочь со статическим синтаксисом, я тогда попытаюсь применить его сам к динамическому коду, в противном случае я Я как бы просил 2 решения в одном)!