推荐学习书目
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 · May 16, 2016 · 2191 views
    This topic created in 3660 days ago, the information mentioned may be changed or developed.

    _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
    
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1071 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 18:05 · PVG 02:05 · LAX 11:05 · JFK 14:05
    ♥ Do have faith in what you're doing.