0

我有以下代码应该读取我的项目所在文件夹中的所有 .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 功能或配置,或者是否有其他功能可以做到这一点?

4

1 回答 1

0

不熟悉 VS,但听起来您的 VS 项目是在与文件所在的目录不同的目录中创建的。和 Jupyter 在同一个目录中。

于 2020-01-29T21:16:35.863 回答