[Python]list.append()在for循环中每次添加的都是最后的一个元素

先贴出源码吧,这段代码我想返回一个list,list中的元素由N个dict组成, dict中会包含目录下文件的名称,大小和最后修改时间(ps.大小和最后修改时间没有贴出来)

import os
def listDirectory(path):
pathlist = []
info = {}
if os.path.isdir(path):
for f in os.listdir(path):
if not f.startswith('.'): #排除隐藏文件
info['name'] = f
pathlist.append(info) #将dict添加进list中
return pathlist,len(pathlist)
else:
return -1,-1

尝试去使用这个函数查询某个文件夹下的内容时,目录文件是如下所示:

lishuo@DELL:~$ ls

connect.sh github nohup.out rjsupplicant tasks 下载

然而,在我调用这个函数去查询某个目录下的文件时,返回的list中只会显示这个文件夹下的最后一个文件,结果如下:

In [1]: from disp_list import listDirectory
In [2]: listDirectory('/home/lishuo')
Out[2]:
([{'name': 'nohup.out'},
{'name': 'nohup.out'},
{'name': 'nohup.out'},
{'name': 'nohup.out'},
{'name': 'nohup.out'},
{'name': 'nohup.out'}],
6)

我感觉问题应该是和python的闭包有关,但是这段代码不知道该从何入手修改?请高手指导,感谢所有花时间阅读我的问题的人^_^

我来补充一点,有点进展,但是不知道为什么?

import os
def listDirectory(path):
pathlist = []
if os.path.isdir(path):
for f in os.listdir(path):
info = {}
if not f.startswith('.'):
info['name'] = f
pathlist.append(info)
return pathlist,len(pathlist)
else:
return -1,-1
结果:
In [1]: from disp_list import listDirectory
In [2]: listDirectory('/home/lishuo')
Out[2]:
([{'name': 'github'},
{'name': 'connect.sh'},
{'name': 'tasks'},
{'name': '\xe4\xb8\x8b\xe8\xbd\xbd'},
{'name': 'rjsupplicant'},
{'name': 'nohup.out'}],
6)

把info字典的定义放在for循环的里面,结果显示就正常了,百度知道查到的但是不知道为什么?字典是可变对象,初始化一定不能放在for循环内部,请问这是为什么?