小编Mit*_*ell的帖子

Timedelta没有定义

以下是我正在处理的代码.据我所知,没有问题,但当我尝试运行这段代码时,我收到一个错误.

import os 
import datetime

def parseOptions():

    import optparse
    parser = optparse.OptionParser(usage= '-h')
    parser.add_option('-t', '--type', \
                      choices= ('Warning', 'Error', 'Information', 'All'), \
                      help= 'The type of error',
                      default= 'Warning')
    parser.add_option('-g', '--goback', \
                      type= 'string')
    (options, args) = parser.parse_args()
    return options

options = parseOptions() now = datetime.datetime.now() subtract = timedelta(hours=options.goback) difference = now - subtract

if options.type=='All' and options.goback==24:
    os.startfile('logfile.htm')

else: 
    print
    print 'Type =', options.type,
    print
    print 'Go Back =', options.goback,'hours'
    print difference.strftime("%H:%M:%S %a, %B %d %Y")
    print
Run Code Online (Sandbox Code Playgroud)

错误如下:

Traceback …
Run Code Online (Sandbox Code Playgroud)

python nameerror python-2.7

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

标签 统计

nameerror ×1

python ×1

python-2.7 ×1