【发布时间】:2018-10-06 06:02:54
【问题描述】:
对不起,我是 Python 3 的新手,我已经在 SO 中一直在寻找答案,但我找不到我的问题的具体答案,而是我可能没有问正确的问题。
我有一个名为 test5.txt 的文件,我在其中写入了我想使用 Python 打开/读取的文件的文件名,即(test2.txt、test3.txt 和 test4.txt)这些 txt 文档具有随机上面的文字。
这是我的代码:
with open("test5.txt") as x:
my_file = x.readlines()
for each_record in my_file:
with open(each_record) as y:
read_files = y.read()
print(read_files)
但遗憾的是我遇到了错误:"OSError: [Errno 22] Invalid argument: 'test2.txt\n'"
【问题讨论】:
-
你检查过这个post吗?
标签: python python-3.x