首页 > 解决方案 > 当我在 python 中循环文件时,结果显示“无”

问题描述

我想遍历一些文件并将这些文件的内容放入一个新列表中,但是当我运行代码时,结果显示“无”。

import os
import glob

folder = os.path.join("R:", os.sep, "Files")
list = []

def notes():

    for file in glob.glob(folder):
        if file.endswith('.docx'):
            with open(file,'r+') as f:
                content = f.read()
                for text in content:
                    new_list = list.append(text)
                return new_list

print(notes())

标签: python

解决方案


推荐阅读