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
61882328
V2EX  ›  Python

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

  •  
  •   61882328 · 2017-05-31 16:39:14 +08:00 · 3057 次点击
    这是一个创建于 2494 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 条回复    2017-06-01 15:44:31 +08:00
    misaka19000
        1
    misaka19000  
       2017-05-31 16:51:00 +08:00 via Android
    写一下不就知道了,我感觉应该是有的
    fszaer
        2
    fszaer  
       2017-05-31 16:51:07 +08:00
    问题只在于把变量声明写在了 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
       2017-05-31 20:29:56 +08:00
    @fszaer 明白了
    SoloCompany
        4
    SoloCompany  
       2017-06-01 00:20:47 +08:00
    这个循环有毒吧,声明了一堆的全局变量出来,或者你只是把混淆的代码前面的那一堆 var 声明给遮住了?
    Rice
        5
    Rice  
       2017-06-01 08:24:49 +08:00
    这是代码混淆后的结果?
    ibufu
        6
    ibufu  
       2017-06-01 13:28:21 +08:00
    这代码有毒,正常人谁会这么写代码
    crashX
        7
    crashX  
       2017-06-01 15:44:31 +08:00
    也就 es6 之前的垃圾语法能这么写,除了 js 没谁了。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3391 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 10:42 · PVG 18:42 · LAX 03:42 · JFK 06:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.