小编Mas*_*ben的帖子

如何在Python中将日期传递给脚本?

我有一个脚本删除比日期更早的图像.

当我打电话来运行脚本时,我可以将此日期作为参数传递吗?

示例:此脚本delete_images.py删除早于日期的图像(YYYY-MM-DD)

python delete_images.py 2010-12-31
Run Code Online (Sandbox Code Playgroud)

脚本(使用固定日期(xDate变量))

import os, glob, time

root = '/home/master/files/' # one specific folder
#root = 'D:\\Vacation\\*'          # or all the subfolders too
# expiration date in the format YYYY-MM-DD

### I have to pass the date from the script ###
xDate = '2010-12-31' 

print '-'*50
for folder in glob.glob(root):
    print folder
    # here .jpg image files, but could be .txt files or whatever
    for image in glob.glob(folder + '/*.jpg'):
        # retrieves the stats …
Run Code Online (Sandbox Code Playgroud)

python date parameter-passing

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

date ×1

parameter-passing ×1

python ×1