今さらPython

UNIXおなじみのコンソールで羽根をクルクル回すやつをPythonでやってみたわ。

コード

#!/usr/bin/env python

import datetime
import time

class Hane():
   def __init__(self):
       self.s = ["/","-","\\","|"]
       self.si = 0
   def next(self):
       self.si = self.si + 1
       if(self.si > 3):
           self.si = 0
       return(str(self.s[self.si]))

h = Hane()
ttx = ""
while 1:
   tx = datetime.datetime.now().strftime("%Y/%m/%d %H:%M:%S")
   if(tx != ttx):
       ttx = tx
       print("\r",flush=True,end="")
       print(tx+" "+h.next(),flush=True,end="")
   time.sleep(0.1)

実行

2023/05/21 16:51:07 /

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2023-05-22 (月) 16:55:31