開発環境
- macOS Mojave - Apple (OS)
- Emacs (Text Editor)
- Windows 10 Pro (OS)
- Visual Studio Code (Text Editor)
- Python 3.7 (プログラミング言語)
入門 Python 3 (Bill Lubanovic (著)、斎藤 康毅 (監修)、長尾 高弘 (翻訳)、オライリージャパン)の10章(システム)、10.5(復習問題)10-1、2、3.を取り組んでみる。
コード(Emacs)
Python 3
#!/usr/bin/env python3
import datetime
import time
print('1.')
today = datetime.date.today()
print(today)
with open('today.txt', 'w') as f:
print(today, file=f)
print('2.')
with open('today.txt') as f:
today_string = f.read().strip()
print(today_string)
print('3.')
print(time.strptime(today_string, '%Y-%m-%d'))
入出力結果(Terminal, cmd(コマンドプロンプト), Jupyter(IPython))
$ ./sample1.py 1. 2018-12-20 2. 2018-12-20 3. time.struct_time(tm_year=2018, tm_mon=12, tm_mday=20, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=3, tm_yday=354, tm_isdst=-1) iMac:ch10 kamimura$ cat today.txt 2018-12-20 $
0 コメント:
コメントを投稿