misc.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:acris 作者: Acrisel 项目源码 文件源码
def touch(path, times=None, dirs=False):
    ''' perform UNIX touch with extra
        based on: http://stackoverflow.com/questions/12654772/create-empty-file-using-python

    Args:
        path: file path to touch
        times: a 2-tuple of the form (atime, mtime) where each member is an int or float expressing seconds.
            defaults to current time.
        dirs: is set, create folders if not exists 
    '''

    if dirs:
        basedir = os.path.dirname(path)
        if not os.path.exists(basedir):
            os.makedirs(basedir)

    with open(path, 'a'):
        os.utime(path, times=times)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号