In memory, the first Python code __python

Source: Internet
Author: User
Work required, learned 2 days python
#! /bin/env python2 # coding:utf-8 ' netnode_list serialized JSON module ' Import JSON from topology import Netnode = '. ./data/topology.json ' class Netnodelistencoder (JSON. Jsonencoder): "Topology list serialization JSON class" "Def default (self, obj):" "" Conversion Method "" "if not Isinstanc
        E (obj,wrapnetnodelistencoder): Raise ValueError (' Netnodelistencoder::p Aram type err! ')
        Return Self._recurse (obj.net_node_list) def _recurse (self, list=[]): "" "Recursive transformation" "L = []
                    If List:for net_node in list:d = net_node.__dict__ if net_node.sub_net: d[' sub_net '] = Self._recurse (net_node.sub_net) Else:del (d[' Sub_ne
        T ']) L.append (d) Return L class Wrapnetnodelistencoder (object): "" "Encapsulation Jsonencoder Exp: Encoder = Wrapnetnodelistencoder (netnode_list) Encoder.encode () # transcoding Encoder.write_jSon () # Write JSON file "" "Def __init__ (self,list=[]): self.net_node_list = list; Self.json_str = ' def encode (self): "" Invoke Netnodelistencoder Encode "" "SELF.JSON_STR = Netno
        Delistencoder (). Encode (self) return self.json_str def Write_json (self): "" Write JSON File "" If Self.json_str.strip (): With open (output_json_file, ' wt ', encoding= ' Utf-8 ') as FD:FD.WR
 ITE (SELF.JSON_STR) else:print ("Wrapnetnodelistencoder::write_json json_str is empty!")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.