Skip to content

Commit

Permalink
添加了index_code
Browse files Browse the repository at this point in the history
  • Loading branch information
ramwin committed Jan 5, 2018
1 parent 8a92f1a commit 0e2266e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -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一致的元素"""
Expand Down Expand Up @@ -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))
}

Expand All @@ -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):
Expand Down

0 comments on commit 0e2266e

Please sign in to comment.