^# [^#\n\r]+$
james=open('C:/Users/skora da_bura/Documents/data.txt')
jake=james.read()
james.close()
numblist=[]
charlist=[]
def Read(numblist,charlist):
for i in range(0,len(jake),4):
numblist.append(int(jake[i]))
for i in range(2,len(jake),4):
charlist.append(jake[i])
Bring = numblist,charlist
james = open('C:/Users/skora da_bura/Documents/data.txt')
jake22 = james.readlines()
james.close()
back='Number of lines read',len(jake22)
return back
print(Read([],[]))
print(charlist)
返回[],即使我在定义函数Read时将附加值添加到列表中也是如此。
我似乎看不出代码有什么问题
答案 0 :(得分:0)
您在#this is not a comment (it is exported as "#this is not a comment")
签名中定义的charlist
遮盖了全局Read
。它们是碰巧具有相同名称的不同变量。如果您打算修改全局变量,则不应尝试将其作为参数传递。