Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ファイルの内容をロードしたら、Python3 でファイルの最初の行を出力するにはどうすればよいですか? 言い換えれば、Python3 の AWK に相当するものは何awk "NR==1"ですか?
awk "NR==1"
ファイルの最初の行を印刷するには、これを試してください:
with open('my_file_name') as in_file: print(next(in_file))
ファイル オブジェクトは、複数行にわたってイテラブルです。したがって、次のような for ループで:
with open('my_file_name') as in_file: for line in in_file: print line
ファイルのすべての行を出力します。