V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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
61882328
V2EX  ›  Python

请教下 js 的这种 for 循环语法怎么改写成 Python 的

  •  
  •   61882328 · May 31, 2017 · 4200 views
    This topic created in 3259 days ago, the information mentioned may be changed or developed.

    python 有下面这段 js 的写法吗?

    
    for (
        d = Math.floor(k.length / 5),
        e = parseInt(k.charAt(d) + k.charAt(2 * d) + k.charAt(3 * d) + k.charAt(4 * d) + k.charAt(5 * d)),
        f = Math.round(b.length / 2),
        g = Math.pow(2, 31) - 1,
        h = parseInt(a.substring(a.length - 8, a.length), 16),
        a = a.substring(0, a.length - 8),
        k += h; k.length > 10;) 
    
    {         
                
        k = (parseInt(k.substring(0, 10)) + parseInt(k.substring(10, k.length))).toString();          
                
    }
    
    7 replies    2017-06-01 15:44:31 +08:00
    misaka19000
        1
    misaka19000  
       May 31, 2017 via Android
    写一下不就知道了,我感觉应该是有的
    fszaer
        2
    fszaer  
       May 31, 2017
    问题只在于把变量声明写在了 for 里而已吧
    ```js
    const d = Math.floor(k.length / 5),
    e = parseInt(k.charAt(d) + k.charAt(2 * d) + k.charAt(3 * d) + k.charAt(4 * d) + k.charAt(5 * d)),
    f = Math.round(b.length / 2),
    g = Math.pow(2, 31) - 1,
    h = parseInt(a.substring(a.length - 8, a.length), 16),
    a = a.substring(0, a.length - 8);

    for (k += h; k.length > 10;) {

    k = (parseInt(k.substring(0, 10)) + parseInt(k.substring(10, k.length))).toString();

    }


    ```

    把它们都提出来的话,不就是一个十分普通的 for 循环而已么?
    61882328
        3
    61882328  
    OP
       May 31, 2017
    @fszaer 明白了
    SoloCompany
        4
    SoloCompany  
       Jun 1, 2017
    这个循环有毒吧,声明了一堆的全局变量出来,或者你只是把混淆的代码前面的那一堆 var 声明给遮住了?
    Rice
        5
    Rice  
       Jun 1, 2017
    这是代码混淆后的结果?
    ibufu
        6
    ibufu  
       Jun 1, 2017
    这代码有毒,正常人谁会这么写代码
    crashX
        7
    crashX  
       Jun 1, 2017
    也就 es6 之前的垃圾语法能这么写,除了 js 没谁了。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1401 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 97ms · UTC 16:28 · PVG 00:28 · LAX 09:28 · JFK 12:28
    ♥ Do have faith in what you're doing.