社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

将javascript函数转换为python

Maxime Morin-Gagnon • 5 年前 • 1712 次点击  

我是python的新手,我很难把这个javascript箭头函数翻译成python。当我找到'\x1d'时,我无法在JS中使用子字符串获取循环中接下来3个值的部分。有什么建议吗?

module.exports = edi => {
  let decompressedEdi = ''
  let lastCompressor = 0
  for (let i = 0; i <= edi.length; i++) {
    if (edi[i] === '\x1D') {
      let decimal = parseInt(edi.substring(i + 1, i + 3), 16)
      let repeater = edi[i + 3]
      decompressedEdi +=
        edi.substring(lastCompressor, i) + repeater.repeat(decimal)
      lastCompressor = i + 4
    }
  }
  decompressedEdi += edi.substring(lastCompressor, edi.length)
  return decompressedEdi.replace(/(\r\n|\n|\r)/gm, '')
}
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/39353
 
1712 次点击  
文章 [ 2 ]  |  最新文章 5 年前