當前位置: 首頁>>代碼示例>>Python>>正文


Python simplejson.OrderedDict方法代碼示例

本文整理匯總了Python中simplejson.OrderedDict方法的典型用法代碼示例。如果您正苦於以下問題:Python simplejson.OrderedDict方法的具體用法?Python simplejson.OrderedDict怎麽用?Python simplejson.OrderedDict使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在simplejson的用法示例。


在下文中一共展示了simplejson.OrderedDict方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: import simplejson [as 別名]
# 或者: from simplejson import OrderedDict [as 別名]
def main():
    if len(sys.argv) == 1:
        infile = sys.stdin
        outfile = sys.stdout
    elif len(sys.argv) == 2:
        infile = open(sys.argv[1], 'r')
        outfile = sys.stdout
    elif len(sys.argv) == 3:
        infile = open(sys.argv[1], 'r')
        outfile = open(sys.argv[2], 'w')
    else:
        raise SystemExit(sys.argv[0] + " [infile [outfile]]")
    with infile:
        try:
            obj = json.load(infile,
                            object_pairs_hook=json.OrderedDict,
                            use_decimal=True)
        except ValueError:
            raise SystemExit(sys.exc_info()[1])
    with outfile:
        json.dump(obj, outfile, sort_keys=True, indent='    ', use_decimal=True)
        outfile.write('\n') 
開發者ID:gkudos,項目名稱:qgis-cartodb,代碼行數:24,代碼來源:tool.py

示例2: test_object_pairs_hook

# 需要導入模塊: import simplejson [as 別名]
# 或者: from simplejson import OrderedDict [as 別名]
def test_object_pairs_hook(self):
        s = '{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
        p = [("xkd", 1), ("kcw", 2), ("art", 3), ("hxm", 4),
             ("qrt", 5), ("pad", 6), ("hoy", 7)]
        self.assertEqual(json.loads(s), eval(s))
        self.assertEqual(json.loads(s, object_pairs_hook=lambda x: x), p)
        self.assertEqual(json.load(StringIO(s),
                                   object_pairs_hook=lambda x: x), p)
        od = json.loads(s, object_pairs_hook=OrderedDict)
        self.assertEqual(od, OrderedDict(p))
        self.assertEqual(type(od), OrderedDict)
        # the object_pairs_hook takes priority over the object_hook
        self.assertEqual(json.loads(s,
                                    object_pairs_hook=OrderedDict,
                                    object_hook=lambda x: None),
                         OrderedDict(p)) 
開發者ID:gkudos,項目名稱:qgis-cartodb,代碼行數:18,代碼來源:test_decode.py

示例3: main

# 需要導入模塊: import simplejson [as 別名]
# 或者: from simplejson import OrderedDict [as 別名]
def main():
    if len(sys.argv) == 1:
        infile = sys.stdin
        outfile = sys.stdout
    elif len(sys.argv) == 2:
        infile = open(sys.argv[1], 'rb')
        outfile = sys.stdout
    elif len(sys.argv) == 3:
        infile = open(sys.argv[1], 'rb')
        outfile = open(sys.argv[2], 'wb')
    else:
        raise SystemExit(sys.argv[0] + " [infile [outfile]]")
    try:
        obj = json.load(infile,
                        object_pairs_hook=json.OrderedDict,
                        use_decimal=True)
    except ValueError, e:
        raise SystemExit(e) 
開發者ID:linuxscout,項目名稱:mishkal,代碼行數:20,代碼來源:tool.py

示例4: render_notification_block

# 需要導入模塊: import simplejson [as 別名]
# 或者: from simplejson import OrderedDict [as 別名]
def render_notification_block(config, env_key, skip_envs=None):
    j2 = get_datadog_jinja_environment()
    template = j2.get_template('notification_block.j2')
    envs = config.env_notifications
    if skip_envs:
        # copy but maintain ordering
        envs = OrderedDict(sorted(config.env_notifications.items()))
        for env in skip_envs:
            envs.pop(env, None)
    return template.render(
        env_key=env_key,
        catchall_alert_channel=config.catchall_alert_channel,
        envs=envs,
        start_block=BLOCK.format(env_key=env_key, start_or_end='START'),
        end_block=BLOCK.format(env_key=env_key, start_or_end='END'),
    ) 
開發者ID:dimagi,項目名稱:commcare-cloud,代碼行數:18,代碼來源:datadog_monitors.py

示例5: main

# 需要導入模塊: import simplejson [as 別名]
# 或者: from simplejson import OrderedDict [as 別名]
def main():
    if len(sys.argv) == 1:
        infile = sys.stdin
        outfile = sys.stdout
    elif len(sys.argv) == 2:
        infile = open(sys.argv[1], 'rb')
        outfile = sys.stdout
    elif len(sys.argv) == 3:
        infile = open(sys.argv[1], 'rb')
        outfile = open(sys.argv[2], 'wb')
    else:
        raise SystemExit(sys.argv[0] + " [infile [outfile]]")
    try:
        try:
            obj = json.load(infile,
                            object_pairs_hook=json.OrderedDict,
                            use_decimal=True)
        except ValueError, e:
            raise SystemExit(e)
        json.dump(obj, outfile, sort_keys=True, indent='    ', use_decimal=True)
        outfile.write('\n') 
開發者ID:uwdata,項目名稱:termite-visualizations,代碼行數:23,代碼來源:tool.py

示例6: test_object_pairs_hook_with_unicode

# 需要導入模塊: import simplejson [as 別名]
# 或者: from simplejson import OrderedDict [as 別名]
def test_object_pairs_hook_with_unicode(self):
        s = u'{"xkd":1, "kcw":2, "art":3, "hxm":4, "qrt":5, "pad":6, "hoy":7}'
        p = [(u"xkd", 1), (u"kcw", 2), (u"art", 3), (u"hxm", 4),
             (u"qrt", 5), (u"pad", 6), (u"hoy", 7)]
        self.assertEqual(json.loads(s), eval(s))
        self.assertEqual(json.loads(s, object_pairs_hook=lambda x: x), p)
        od = json.loads(s, object_pairs_hook=json.OrderedDict)
        self.assertEqual(od, json.OrderedDict(p))
        self.assertEqual(type(od), json.OrderedDict)
        # the object_pairs_hook takes priority over the object_hook
        self.assertEqual(json.loads(s,
                                    object_pairs_hook=json.OrderedDict,
                                    object_hook=lambda x: None),
                         json.OrderedDict(p)) 
開發者ID:gkudos,項目名稱:qgis-cartodb,代碼行數:16,代碼來源:test_unicode.py

示例7: get_config

# 需要導入模塊: import simplejson [as 別名]
# 或者: from simplejson import OrderedDict [as 別名]
def get_config(config_path):
    with open(config_path, 'r') as config_file:
        config = Config(yaml.safe_load(config_file))
        config.env_notifications = OrderedDict(sorted(config.env_notifications.items()))
    return config 
開發者ID:dimagi,項目名稱:commcare-cloud,代碼行數:7,代碼來源:datadog_monitors.py


注:本文中的simplejson.OrderedDict方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。