这是我的密码。当我运行它时,它只是在运行后退出。什么都没有印出来。为什么?在
def checkString(filename, string):
input = file(filename) # read only will be default file permission
found = False
searchString = string
for line in input:
if searchString in line:
found = True
break
if callfunc == 'initialize':
print listdir() #this will print list of files
print "\n"
for files in listdir():
checkString(files,"hello")
if found:
print "String found"
else:
print "String not found"
input.close()
found
是函数checkString()
中的一个local名称;它保持本地名称,因为您不返回它。在从函数返回变量并存储返回值:
您需要修改为:
这是因为在原来的
found
只在函数checkString
的作用域内相关问题 更多 >
编程相关推荐