![]() The C version's OrderedDict.popitem may call your _getitem_ which then does deletion and emit KeyError when expires. I think your expiringdict seems not work with the C version OrderedDict, you may need to change your implementation or clarify that :(. ![]() Replacing use of popitem() with "del self" removes the KeyErrors and the structure otherwise works fine. ![]() :(Īuthor: Serhiy Storchaka (serhiy.storchaka) *Ī frequent reproducer is to run the expiringdict tests on Python 3.5.1, unfortunately I cannot come up with a testcase. The C-based optimised version of collections.OrderedDict occasionally throws KeyErrors when deleting items.īackporting 3.6's patches to 3.5.1 does not resolve the issue. I write about random things that come to mind, mostly for my future self and any visitor who might find useful.KeyError thrown by optimised ()ĭennis Sweeney, eric.snow, josh.r, kaniini, lukasz.langa, methane, python-dev, rhettinger, serhiy.storchaka, xiang.zhang, zach.wareĬreated on 04:33 by kaniini, last changed 14:58 by admin. ![]() « Convert Python objects to JSON Improved Priority Queue recipe in Python » About Me Posted by Cuong Dong-Si May 25 th, 2016 1:26 am python dump ( config, config_file, default = lambda o : vars ( o ), indent = 4 ) def main (): FILE_NAME = "hive_vertica_count.json" query_generator = generate_count_queries () create_config_file ( FILE_NAME, query_generator ) if _name_ = "_main_" : main () queries = query_generator with open ( filename, 'w' ) as config_file : json. url = "jdbc:vertica://192.168.5.174:5433/VMart" return conn def create_config_file ( filename, query_generator ): hive_source = get_hive_config () vertica_target = get_vertica_config () config = Config () config. url = "jdbc:hive2://192.168.5.184:10000/DWH" return conn def get_vertica_config (): """ Get pre-defined Vertica configuration. _dict_ = value pass def get_hive_config (): """ Get pre-defined Hive configuration. _dict_ def _setattr_ ( self, key, value ): self. OrderedDict () def _getattr_ ( self, item ): return self. Import collections import json class Config ( object ): ODICT = "odict" def _init_ ( self ): self. This option is just a quick and dirty workaround: our Config class should extend collections.OrderedDict class and, in the code, we refer to object instead of object.att. To have the keys appear in order as defined when converting to JSON, we have two options: Option 1: use OrderedDict as your base class Setting sort_keys option in json.dump is not applicable here since the keys will be sorted by their names, not their order of appearance like we do in the Java example. However, it sometimes makes sense to humans for the keys to be pretty-printed in order, especially when we need to look for two keys in JSON next to each other or one key before another.įor example, in the Config object in the last post, it is better to see source and target configurations side by side and, then, get to know what kind of tests from testName key before reading details of tests in queries key. In theory, it does not matter to machines when converting to/from JSON. In the JSON output shown in the last post, the keys are printed out of order since they are unordered in the internal dictionary _dict_.
0 Comments
Leave a Reply. |