質問編集履歴
2
もう一度載せなおしました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,2 +1,23 @@
|
|
1
|
+
"text"というフォルダーの中に5つのテキストファイルがあり、内容すべてをprintしたいです。しかし、エラーが出ます。
|
2
|
+
|
3
|
+
```ここに言語を入力
|
4
|
+
import os
|
5
|
+
|
6
|
+
path = '/mnt/c/Users/4345k/Desktop/coursework/RC101/text'
|
1
|
-
|
7
|
+
path_list = os.listdir(path)
|
2
|
-
|
8
|
+
for path in path_list:
|
9
|
+
f = open(path,'r')
|
10
|
+
lines = f.readlines()
|
11
|
+
for line in lines:
|
12
|
+
print(line)
|
13
|
+
f.close()
|
14
|
+
```
|
15
|
+
FileNotFoundError Traceback (most recent call last)
|
16
|
+
<ipython-input-25-e76fd6602cb6> in <module>
|
17
|
+
4 path_list = os.listdir(path)
|
18
|
+
5 for path in path_list:
|
19
|
+
----> 6 f = open(path,'r')
|
20
|
+
7 lines = f.readlines()
|
21
|
+
8 for line in lines:
|
22
|
+
|
23
|
+
FileNotFoundError: [Errno 2] No such file or directory: 't2.txt'
|
1
解決しました
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,23 +1,2 @@
|
|
1
|
-
textというファイルの中に5個のtxtファイルが入っているんですけど、それをすべてプリントしたいです。しかし、できません;;原因は何ですか...
|
2
|
-
|
3
|
-
```ここに言語を入力
|
4
|
-
import os
|
5
|
-
|
6
|
-
path = '/mnt/c/Users/4345k/Desktop/coursework/RC101/text'
|
7
|
-
|
1
|
+
すみません解決しました。回答してくださった方々、ありがとうございました。
|
8
|
-
|
2
|
+
質問をすべて消してしまい、すみませんでした。
|
9
|
-
f = open(path,'r')
|
10
|
-
lines = f.readlines()
|
11
|
-
for line in lines:
|
12
|
-
print(line)
|
13
|
-
f.close()
|
14
|
-
```
|
15
|
-
FileNotFoundError Traceback (most recent call last)
|
16
|
-
<ipython-input-25-e76fd6602cb6> in <module>
|
17
|
-
4 path_list = os.listdir(path)
|
18
|
-
5 for path in path_list:
|
19
|
-
----> 6 f = open(path,'r')
|
20
|
-
7 lines = f.readlines()
|
21
|
-
8 for line in lines:
|
22
|
-
|
23
|
-
FileNotFoundError: [Errno 2] No such file or directory: 't2.txt'
|