我正在尝试制作一种编程语言,但是运行它时出现错误IndexError: list index out of range
,错误发生在cw = (L[words])
上,准备进行连接。我该如何解决?
我尝试过join()
,StringIO
,str+str
,.concat
和.append
def echo(filename):
try:
with open(filename,'r') as myFile:
for line in myFile:
sentence = line
L = sentence.split()
t = L
words = 1
wc = len(sentence.split())
wc3 = float(wc)
output = ''
cw = ''
for i in range(0, wc):
cw = (L[words])
output.join(cw)
words=words+1
if L[0]=='echo':
print(output)