From 0e2266e84c3e4783bd11d5ca7d4856e6176d186d Mon Sep 17 00:00:00 2001 From: Xiang Wang Date: Fri, 5 Jan 2018 18:26:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=BA=86index=5Fcode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convert.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/convert.py b/convert.py index 2c354ad..6757b3d 100644 --- a/convert.py +++ b/convert.py @@ -14,11 +14,12 @@ class Industry(object): """代表了行业的类""" - def __init__(self, name, code, parent=None): + def __init__(self, name, code, parent=None, index_code=None): self.name = name.strip() self.code = str(code) self.parent = parent self.children = [] + self.index_code = index_code def has_child(self, industry): """self的children里面是存在code和industry的code一致的元素""" @@ -105,6 +106,7 @@ def to_dict(self): return { 'code': self.code, 'name': self.name, + 'index_code': self.index_code, 'children': list(map(lambda x: x.to_dict(), self.children)) } @@ -115,7 +117,7 @@ def main(): reader = csv.DictReader(open(file_name), delimiter=' ') print(reader.fieldnames) industry_list = list(map( - lambda x: Industry(name=x['name'], code=x['code']), + lambda x: Industry(name=x['name'], code=x['code'], index_code=x['index_code']), reader)) # 添加一级行业 for index, industry in enumerate(industry_list):