Py学习  »  Python

将javascript函数转换为python

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

我是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
 
1687 次点击  
文章 [ 2 ]  |  最新文章 5 年前