3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Python Printで改行せずに処理経過を表示

Posted at

print文で改行しない方法

引数end=""とすればOK

print("表示する文字",end="")

行頭に戻る方法

エスケープシーケンス 「\r」を付けます。

print("\r表示する文字",end="")

処理ループに組み込み

stime = time.time()

num = len(iter)
for i, r in enumerate(iter):
    etime = time.time()
    print("\r time:",int(etime-stime),'sec ',i+1,"/",num, end="")
    # 処理内容
print('') # 最後に改行

結果

以下のカウンタが同じ行で表示されます。

time: 19 sec  346 / 1855
3
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?