Best way to 'touch' a file?

Fredrik Lundh fredrik at
Mon Aug 22 23:12:32 CEST 2005

Peter Hansen wrote:

> from path import path
> path('myfile').touch()

import os
os.utime('myfile', None)

is a bit shorter, of course.

>>> help(os.utime)
Help on built-in function utime:

    utime(path, (atime, utime))
    utime(path, None)

    Set the access and modified time of the file to the given values.  If 
    second form is used, set the access and modified times to the current 


More information about the Python-list mailing list