python - 在 python 中使用列表理解获取完整路径名

标签 python python-3.x

我可以做这样的事情吗(实际上它不起作用)

flist = [dirpath + f for f for fnames for dirpath, dirnames, fnames in os.walk('/home/user')]

谢谢!

最佳答案

fnames 尚不存在。交换循环。

flist = [dirpath + f for dirpath, dirnames, fnames in os.walk('/home/user') for f in fnames]

关于python - 在 python 中使用列表理解获取完整路径名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6278369/

相关文章:

python - Django - 通过Ajax发布jQuery字典在views.py中打印None

python - 使用带修饰协程的单个事件循环返回 future 结果

python - 减少 python 中的循环

python - 值错误 : scatter requires x column to be numeric

python - openAi-gym 名称错误

python 字符串在一行

python - Django 模板如果类型添加到 html id

python - Conda 不会让我激活环境

python - 为什么 QListView 在尝试检索文本时给我一个 NoneType ?

python-3.x - ImageDataGenerator 未定义