回答編集履歴

1

回答修正

2019/04/12 09:38

投稿

can110
can110

スコア38266

test CHANGED
@@ -1 +1,23 @@
1
- たしか`subprocess.check_output`の戻り値はリストだったと思うので、`result[-1]`で末尾行のみ取り出せます。
1
+ ~~たしか`subprocess.check_output`の戻り値はリストだったと思うので、`result[-1]`で末尾行のみ取り出せます。~~
2
+
3
+
4
+
5
+ 以下のようなコードで末尾行のみ取得できます。
6
+
7
+ ```Python
8
+
9
+ result = b'abcd\nID=efgh\n' # テスト
10
+
11
+
12
+
13
+ result = result.decode()
14
+
15
+ result.replace('\r','') # windows環境などは改行が\r\n
16
+
17
+ result = result.rstrip() # 末尾が改行なら除去
18
+
19
+ result = result.split('\n')
20
+
21
+ print(result[-1])
22
+
23
+ ```