如何优化内嵌函数?

2016-05-16 23:34:01 +08:00
 explist

_sep()内嵌函数如何优化下,感觉不够简洁优雅

def lumpCalc_sep(self,record,oday):

    pre = record.day
    mon = record.month
    next = dateAddmonth(pre,mon)
    sum = record.money
    sep = []
    
    def _sep():
        nonlocal sum,sep,pre,next,self,mon
        i = self.table.icor(pre)
        r = 0.0 if i<0 else self.table.getTheIrate(i,mon)
        sqx = _preint(r,sum,mon)
        s = self.tax(pre,next,sum,r)
        sep.append([pre,next,sum,r,sqx,s])            
        sum += (sqx-s)
        pre = next
        
    if oday >= next:
        _sep()
        mon = record.again
        if mon != 0:
            next = dateAddmonth(next,mon)
            while oday >= next:
                _sep()
                next = dateAddmonth(next,mon)
    if pre != oday:
        cur = self.cur_tax_later_sep(pre,oday,sum)
        sep.append([pre,oday,sum,cur[1][0],cur[1][1],cur[1][2]])
        sum += cur[0]
    return sum,sep
1843 次点击
所在节点    Python
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/279097

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX