我有以下代码:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys import re
companies = {}
for line in open('/home/ibrahim/Desktop/Test.list'):
company, founding_year, number_of_employee = line.split(',')
number, name = company.split(")")
companies[name] = [name, founding_year, number_of_employee]
print "Company: %s" % company
CompanyIndex = raw_input('\n<Choose a company you want to know more about.>\n\n<Insert a companyspecific-number and press "Enter" .>\n')
if CompanyIndex in companies:
name, founding_year, number_of_employee = companies[CompanyIndex]
print 'The companys name is: ',name,'\nThe founding year is: ', founding_year,'\nThe amount of employees is: ', number_of_employee
else:
print"Your input is wrong."
该程序从如下所示的文本文件中读取一些信息:
(1)Chef,1956,10
(2)Fisher,1995,20
(3)Gardener,1998,50
我的目标是创建一个类,我可以在其中保存有关公司名称、成立年份和员工人数的信息,而不是使用包含列表的字典。
我阅读了几个教程,但我真的不知道该怎么做。__init__
这个“自我”是什么,做了什么__del__
等等,真是令人困惑。我该怎么做呢?