ich Python-Code so etwas wie haben:getopts Werte Klasse und Template.Substitute nicht (sofort) zusammenarbeiten, um
from string import Template
import optparse
def main():
usage = "usage: %prog options outputname"
p = optparse.OptionParser(usage)
p.add_option('--optiona', '-a', default="")
p.add_option('--optionb', '-b', default="")
options, arguments = p.parse_args()
t = Template('Option a is ${optiona} option b is ${optionb}')
print t.substitute(options)
Aber das gibt mir
AttributeError: Values instance has no attribute '__getitem__'
Da options
A-Werte und nicht ein Wörterbuch.
Wie ordentlich ich diese Arbeit machen?
(andere Vorschläge willkommen, mein pythonic Sinn noch gepflegt wird ...)
Dank . Ich wusste, dass es nur ein paar Zeichen lang sein würde ... – Greg