下面在Windows中的Python 3.8上的代码可以根据需要工作,但它将数字输出到STDOUT,我不知道为什么。它递归读取目录并正确输出到文本文件
import os
targpath = "C:\\users\\ReedActed\\desktop\\" # To direct location of target file
with open(targpath + 'P-drive-test.txt', 'w', encoding='utf-8') as outfile:
for r, d, f in os.walk('P:\\backup\\'):
for file in f:
fileneat = os.path.join(r, file) + "\n" # Needs the line break
outfile.write(fileneat)
文件看起来是正确的,但在STDOUT中,我得到以下信息:
99
65
75
47
41
33
什么在创建标准输出?这不是问题,只是好奇
这个答案确实指向juanpa arrivillaga,但看起来outfile.write()的结果将返回由于它位于REPL中而写入的字节数。谢谢你的解决方案
相关问题 更多 >
编程相关推荐