1
インラインデータを使用してファイルからデータを読み込むスクリプトをテストすると便利です(データとコードの両方が同じファイルになるように)。 bash
、これはheredoc
で行うことができます。データ入力用のbash-like heredoc
while read l;do
echo $l
done << EOF
test
test2
test3
EOF
いくつかの実際のコードでは、もちろん、より離れて行を書いてから何かが起こるでしょう。私はpython
に似た何かをするだろうとします
def read_file(f):
for line in f.readlines():
print(line.replace('\n',''))
with open('input.txt') as f:
read_file(f)
input.txt
read_file()
にインラインのコンテンツを提供するための最良の方法だろうか?