LoginSignup
0
0

More than 5 years have passed since last update.

PACEMAKER > Python2 > fileIO > /tmp/capture_motionがあれば日付を表示 | なければ作る (touchに相当する処理)

Last updated at Posted at 2017-11-05
動作環境
Raspberry Pi 2 Model B (以下RPi)
Raspbian Jessie
Python 2.7.9

プロジェクト開始: link

処理

  • /tmp/capture_motionファイルの有無を確認
    • あれば
      • ファイルの更新日時を取得
    • なければ
      • ファイルを作る

参考

code

welcomeBack_171105.py
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import os.path
import time
from datetime import datetime as dt

"""
v0.1 Nov. 05, 2017
   - touch file
   - read file datetime
"""

filepath = "/tmp/capture_motion"
if os.path.exists(filepath):
    mddt = time.ctime(os.path.getmtime(filepath))
    print(mddt)
else:
    with open(filepath, 'a'):
        os.utime(filepath, None)

run
$ python welcomeBack_171105.py 
$ python welcomeBack_171105.py 
Sun Nov  5 19:23:37 2017
$ python welcomeBack_171105.py 
Sun Nov  5 19:23:37 2017
0
0
0

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
0
0