我在函数中有以下内容:
edu = sorted(context.education, key=lambda studied: studied["studied_to"], reverse=True)
#print edu[0].studied_to
job_history = []
for job in context.job_history:
if edu[0].fields_of_study in job.industries:
from_ = job.from_
to_ = job.to_
industries = job.industries
rd = rdelta.relativedelta(to_, from_) # get date difference
# I suspect that combined exp calculation would be done here.
experience = "{0.years} Years {0.months} Months".format(rd) #get Year - Month format
#print experience
job_history.append({"job_title": job_title,
"company_name": company_name,
"from_": from_,
"to_": to_,
"industries": industries,
"experience": experience})
j = sorted(job_history, key=lambda s: s["to_"])
#print j[0]["job_title"]
return {"relocate_list": provinces,
"disabilities_dict": disabilities,
"industries_list": industry_dict,
"job_history_sorted": j,
"education_sorted": edu}
我可以通过上面的代码获得每项工作的经验。有没有办法计算综合经验。
目前,为了论证,用户在IT行业中拥有/拥有多个工作,以上代码将给我提供,例如1 Years 0 Months
和1 Years 4 Months
。
如何计算综合体验,以便上面的示例为2 Years 4 Months
?
我试过了:
rd += rd
但是这增加了相同的日期,即
1 Years 4 Months + 1 Years 4 Months
会输出:
2 Years 8 Months
答案 0 :(得分:1)
为什么不创建一个新变量来保存相对增量并将其显示在循环外部,例如:
job_history = []
total_exp = rdelta.relativedelta()
for job in context.job_history:
if edu[0].fields_of_study in job.industries:
from_ = job.from_
to_ = job.to_
industries = job.industries
rd = rdelta.relativedelta(to_, from_) # get date difference
total_exp += rd
job_history.append({"job_title": job_title,
"company_name": company_name,
"from_": from_,
"to_": to_,
"industries": industries,
"experience": experience})
# I suspect that combined exp calculation would be done here.
experience = "{0.years} Years {0.months} Months".format(total_exp) #get Year - Month format
#print experience