このスクリプトは、割り当て用の別のスクリプトに基づいています。私のコードは彼らのコードと同じように見え、両方とも構文エラーでエラーになります。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
>>>
ご覧いただきありがとうございます。