我有以下代码应该读取我的项目所在文件夹中的所有 .txt 文件(我在 Visual Studio Code 中执行此操作):
for file in glob.glob("*.txt"):
fp = open(file, "r", -1, 'utf-8')
text= fp.readlines()
print(file, "->", text)
我想读取我文件夹中的所有文件(不通知目录).txt,但此功能在 Visual Studio 中无法正常工作,但它在 Jupyter 笔记本中完美运行。
textjupyter notebook中变量的输出/内容
file1.txt -> ["this phrase is in file 1"]
file2.txt -> ["this phrase is in file 2"]
file3.txt -> ["this phrase is in file 3"]
有谁知道我是否忘记了 Visual Studio 功能或配置,或者是否有其他功能可以做到这一点?