V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
explist
V2EX  ›  Python

如何优化内嵌函数?

  •  
  •   explist · 2016-05-16 23:34:01 +08:00 · 1809 次点击
    这是一个创建于 2908 天前的主题,其中的信息可能已经有所发展或是发生改变。

    _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
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2078 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 16:04 · PVG 00:04 · LAX 09:04 · JFK 12:04
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.