teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

コード記載

2020/07/08 06:37

投稿

jeanbiego
jeanbiego

スコア3966

answer CHANGED
@@ -1,1 +1,18 @@
1
- 行数がほしいなら、count=len(line)でどうですか。
1
+ 行数がほしいなら、count=len(line)でどうですか。
2
+
3
+ 4行に対して、4と出ます。1と出るのはなにか間違えているのではないでしょうか。
4
+ ```python3
5
+ import io
6
+ txt = """a
7
+ b
8
+ c
9
+ d
10
+ """
11
+
12
+ f = io.StringIO(txt)
13
+ lines = f.readlines()
14
+ f.close()
15
+ count = len(lines)
16
+ print(count)
17
+ # 4
18
+ ```