Py学习  »  Python

Katana(python):编码问题还是bug?

Ellis Hogan • 6 年前 • 1623 次点击  

好的,这是密码。我不打算在日志中键入错误。不需要复制代码。它的基本意思是存在一个问题,即“l”不是int类型。

def i_am_here(path):
  print(path)
  lst = []
  num = []
  x = 0
  y = 0
  for i in path:
    try: 
        int(i)
        num.append(int(i))
    except ValueError:
        if i == 'r' or i == 'R':
            new = ''.join(num)
            lst.append(new)
            lst.append('r')
            num = []
        if i == 'L' or i == 'l':
            new = ''.join(num)
            lst.append(new)
            lst.append('l')
            num = []
  new = ''.join(num)
  lst.append(new)
  lst = lst[1:len(lst)]
  print(lst)
  for i in range(len(lst)):

    if lst[i] == 'r':
        print(lst[i+1])

enter image description here

好的,所以我99%确定这只是一个错误,当我使用:

for i in path:
    try: 
        int(i)
        num.append(int(i))
    except ValueError:
        if i == 'r' or i == 'R':

            lst.append(num)
            lst.append('r')
            num = []
        if i == 'L' or i == 'l':

            lst.append(num)
            lst.append('l')
            num = []

一切正常。有什么想法吗?我本来打算提交一张发行票,但在提交之前我想我可能会问。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/43155
 
1623 次点击  
文章 [ 2 ]  |  最新文章 6 年前