我做了一个小的“控制台”,将命令拆分为.我将“命令”(第一个“单词”与)与第一个单词后面的“参数”分开。下面是生成错误的代码:split()input()
cmdCompl = input(prompt).strip().split()
cmdRaw = cmdCompl[0]
args = addArgsToList(cmdCompl)
addArgsToList()功能:
def addArgsToList(lst=[]):
newList = []
for i in range(len(lst)):
newList.append(lst[i+1])
return newList
我尝试将后面的每个单词添加到由 返回的列表中。但我得到的是:cmdRawargsaddArgsToList()
Welcome to the test console!
Type help or ? for a list of commands
testconsole >>> help
Traceback (most recent call last):
File "testconsole.py", line 25, in <module>
args = addArgsToList(cmdCompl)
File "testconsole.py", line 15, in addArgsToList
newList.append(lst[i+1])
IndexError: list index out of range
我不知道为什么我会得到一个,因为据我所知,可以动态分配。IndexErrornewList
有什么帮助吗?
慕妹3146593
慕勒3428872
相关分类