program1.py:stdinは文字列のように単語単位ではなく行単位で読み込まれるのはなぜですか?
a = "this is a test"
for x in a:
print(x)
program2.py:
a = """this is a test
with more than one line
three, to be exact"""
for x in a:
print(x)
program3.py:
import sys
for x in sys.stdin:
print(x)
infile.txt:これはテスト
ある
複数行
第二の例として、ちょうど同じ
とが、複数の単語
はなぜ個別の行に文字列の各文字は、プログラム1とPROGRAM2出力の両方を行うことが、私たちはcat infile.txt | python3 program3.py
を実行した場合、それを出力して行ごとのテキスト?
sys.stdin'が文字列でない '理由 - それは行ずつを読み取るように構成された特殊なクラスです。 – furas
'sys.stdin'は' str' *オブジェクトではなく、ファイルオブジェクトです。 –