Last active
October 25, 2016 02:30
-
-
Save mr-ice/a693375f4a05b4e6e19ebead27948218 to your computer and use it in GitHub Desktop.
json OrderedDict vs json sort_keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> import json | |
>>> from collections import OrderedDict | |
>>> d = json.load(file('cards.json'), object_pairs_hook=OrderedDict) | |
>>> 'count' in d[333] | |
False | |
>>> d[333]['count'] = 10 | |
>>> print(json.dumps(d[333],indent=4)) | |
{ | |
"cardset": "empires", | |
"cost": "5", | |
"description": "+1 Card\n +1 Action\n______________________\nWhile this is in play, when you gain a Victory card, +1<VP>", | |
"extra": "This can trigger multiple times in a turn, for cards gained different ways. For example you could play Groundskeeper, then play Engineer gaining an Estate and taking 1<VP>, then in your Buy phase buy a Duchy taking another +1<VP>. Multiple Groundskeepers are cumulative. If you Crown a Groundskeeper, there is still just one Groundskeeper in play, so you only get +1<VP> per Victory card gained.", | |
"name": "Groundskeeper", | |
"potcost": 0, | |
"types": [ | |
"Action" | |
], | |
"count": 10 | |
} | |
>>> print(json.dumps(d[333],indent=4, sort_keys=True)) | |
{ | |
"cardset": "empires", | |
"cost": "5", | |
"count": 10, | |
"description": "+1 Card\n +1 Action\n______________________\nWhile this is in play, when you gain a Victory card, +1<VP>", | |
"extra": "This can trigger multiple times in a turn, for cards gained different ways. For example you could play Groundskeeper, then play Engineer gaining an Estate and taking 1<VP>, then in your Buy phase buy a Duchy taking another +1<VP>. Multiple Groundskeepers are cumulative. If you Crown a Groundskeeper, there is still just one Groundskeeper in play, so you only get +1<VP> per Victory card gained.", | |
"name": "Groundskeeper", | |
"potcost": 0, | |
"types": [ | |
"Action" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment