这个脚本是基于另一个任务的。我的代码看起来和他们的一样,并且都出现语法错误。我正在运行 ActiveState Active Python 2.7 64 位
def showEvents():
''' showEvents command
List events from event logger with the following options:
-t or -type (type of event to search for)
warning (default option)
error
information
all
-g or -goback (time in hours to search)
integer
default is 100 hours
>>>showEvents -t warning -g 100
type = warning
goBack = 100 hours
'''
import optparse
parser = optparse.OptionParser()
parser.add_option('-t', '--type', \
choices=('error', 'warning', 'information', 'all' ), \
help='write type to eventType',
default = 'warning')
parser.add_option('-g', '--goback', \
help='write goback to goback',
default = '100')
(options, args) = parser.parse_args()
return options
options = showEvents()
print 'type = ', options.type
print 'goBack =', options.goback, 'hours'
if options.type == 'all':
if options.goback == '24':
import os
os.startfile('logfile.htm')
这将在运行时返回默认值,但不会接受输入。我错过了什么?
>>> type = warning
goBack = 100 hours
>>> showEvents -t error
Traceback ( File "<interactive input>", line 1
showEvents -t error
^
SyntaxError: invalid syntax
>>>
感谢您的关注。