Skip to content

Instantly share code, notes, and snippets.

@devlights
Created March 22, 2018 02:42
Show Gist options
  • Save devlights/e0cd652010d6d322d27f871fb95d6fc4 to your computer and use it in GitHub Desktop.
Save devlights/e0cd652010d6d322d27f871fb95d6fc4 to your computer and use it in GitHub Desktop.
[python] コンソールに現在日時を表示し続けるスクリプト
import datetime as dt
import time as tm
import sys
def go():
while True:
d = dt.datetime.now()
now = d.strftime('%Y/%m/%d %H:%M:%S')
sys.stdout.write(f'\r{now}')
sys.stdout.flush()
tm.sleep(1)
if __name__ == '__main__':
go()
@devlights
Copy link
Author

たまに重宝してるプチスクリプト。

python2で動作させる場合は

sys.stdout.write(f'\r{now}')

の部分を

sys.stdout.write("\r%s" % now)

に変更する。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment