ファイルを読み込んで、1行目だけをコンソールに出力するには readlines() を使う。
例
f = open("data.txt") lines = f.readlines() print(lines[0][:-1]) f.close()
読み込みファイル
data.txt の中身は
1 2 3 4 5 6 7 8 9
結果
1 2 3
雑記
投稿日:
ファイルを読み込んで、1行目だけをコンソールに出力するには readlines() を使う。
f = open("data.txt") lines = f.readlines() print(lines[0][:-1]) f.close()
data.txt の中身は
1 2 3 4 5 6 7 8 9
1 2 3
執筆者:seyanen
関連記事
mac の convert コマンドで画像ファイルをサイズ変更する
convert コマンドを使うには、imagemagick というソフトがインストールされていることが必要。 インストールの確認 $ which convert で、imagemagick がインスト …
斜めの点列を \ddots として書くのがコツ。\matrix を使うためにパッケージ amsmath を使う。 例 \usepackage{amsmath} \begin{document} $$ …
量子科学では、「プランク定数」を h で表すが、h を 2π で割った量を エイチバーで表すことがある。 tex での書き方 $\hbar$ 結果 リベンジH 4【電子書籍】[ 仙道ますみ ]価格:6 …
テキストを \flushright で囲めば良い。 例 \begin{flushright} Lorem, ipsum dolor sit amet consectetur adipisicing e …
2023/01/18
matplotlib のグラフ作成と gnuplot との対応 比較
2022/10/14
pythonで配列(リスト)の、ある要素がわかっているときにその次の要素を取得する方法。