【问题标题】:Convert struct_time to String in python has error在python中将struct_time转换为String有错误
【发布时间】:2018-08-23 07:36:45
【问题描述】:

我使用如下代码运行 my.py 20180822 以将 struct_time 转换为字符串

def mkdate(datestr):
    return time.strptime(datestr, '%Y%m%d')

parser = argparse.ArgumentParser(description='Download Images from Web Site')
parser.add_argument('startDate',type=mkdate, nargs='*', help='Start Date to Download')

    if args.startDate:
        startDate = time.strftime('%Y%m%d', args.startDate)

我收到如下错误,虽然我用谷歌搜索但没有任何答案,我该怎么办...

    [time.struct_time(tm_year=2018, tm_mon=8, tm_mday=22, tm_hour=0, tm_min=0, tm_sec=0, tm_wday=2, tm_yday=234, tm_isdst=-1)]
2018/08/23 16:21:28 ERROR    Exception: Traceback (most recent call last):
  File "C:\My.py", line 8, in main
    startDate = time.strftime('%Y%m%d', args.startDate)
TypeError: Tuple or struct_time argument required

【问题讨论】:

  • 我得到了我需要的东西,它是

标签: python-3.x time argparse strptime strftime


【解决方案1】:

我得到了我需要的,就是

startDate = time.strftime('%Y%m%d', args.startDate[0])

【讨论】:

    猜你喜欢
    • 2017-08-20
    • 1970-01-01
    • 1970-01-01
    • 2019-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多