【发布时间】:2020-04-05 12:44:05
【问题描述】:
from pathlib import Path, PureWindowsPath
path=Path(PureWindowsPath('c:/test'))
print(file for file in path.glob('*.*'))
print("\n")
for file in path.glob('*.*'):print(file)
我是一个学习 python 的菜鸟,我无法理解 for 循环和结果之间的区别。我在一个中获取生成器对象,在另一个中获取文件名。
结果是:
<generator object <genexpr> at 0x000002D8446B3970>
c:\test\Changes.xlsx
c:\test\North Accounts V1.1.xlsx
c:\test\North Customer Contact Details.xlsx
c:\test\Py_Test.xlsx
进程以退出代码 0 结束
【问题讨论】:
标签: python path generator pathlib