開発環境
- macOS High Sierra - Apple
- Emacs (Text Editor)
- Python 3.6 (プログラミング言語)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の10章(システム)、10.5(復習問題)1、2、3.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3 import datetime import time print('10-1') filename = 'today.txt' with open(filename, 'w') as f: print(datetime.date.today().isoformat(), file=f, end='') print('10-2') with open(filename) as f: today_string = f.read() print(today_string) print('10-3') fmt = "%Y-%m-%d" t = time.strptime(today_string, fmt) print(t) print(f'{t.tm_mon}月{t.tm_mday}日')
入出力結果(Terminal, Jupyter(IPython))
$ ./sample1.py 10-1 10-2 2018-05-29 10-3 time.struct_time(tm_year=2018, tm_mon=5, tm_mday=29, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=1, tm_yday=149, tm_isdst=-1) 5月29日 $
0 コメント:
コメントを投稿