Automatische Hilfe von `optparse`
Verfasst: Dienstag 30. Januar 2007, 21:53
Hallo,
im Zuge der Entwicklung meines derzeitigen Projekts hab ich mich mit optparse auseinadergesetzt. Nur bekomme ich bei diesem Code einen Fehler, wenn ich die automatisch generierte Hilfe benutzen möchteFehlerausgabe:Nur hab ich selber kein Tupel eingebaut - oder ich finde es nicht. Ist das ein Bug von optparse? Was hab ich falsch gemacht? 
Bitte klärt mich mal auf
LG Tobi
im Zuge der Entwicklung meines derzeitigen Projekts hab ich mich mit optparse auseinadergesetzt. Nur bekomme ich bei diesem Code einen Fehler, wenn ich die automatisch generierte Hilfe benutzen möchte
Code: Alles auswählen
def main():
u = "usage: %prog [options] DIR"
v = "%prog",__version__
d = "This programm deletes the *.txt files and renames the *.jpg",
"file of all Jamendo subdirs in the given directory. It also creates",
"playlists of the albums and if requestet of all albums from a author.",
"You have also the possibility to change the directorytree."
h={"-c":"prevents the renaming of the *.jpg file into cover.jpg.",
"-t":"prevents the deleting of the *.txt files.",
"-a":"tells the programm to change only the directoryname not the tree.",
"-f":"cuts off the Jamendo text after the two hyphens.",
"-v":"prints exactly what's being done.",
"-p":"prevents the creating of playlists",
"-d":"the folder DIR which contains the downloaded albumbs"}
parser = OptionParser(usage=u, version=v, description=d,
add_help_option=True)
parser.add_option("-f", "--folderrename", action="store_true",
dest="folderrename", default=False, help=h["-d"])
parser.add_option("-v", "--verbose", action="store_true",
dest="verbose", default=False, help=h["-v"])
parser.add_option("-t", "--notxtdelete", action="store_false",
dest="txtdelete", default=True, help=h["-t"])
parser.add_option("-a", "--noartistdirs", action="store_false",
dest="artistdir", default=True, help=h["-a"])
parser.add_option("-c", "--nocorrename", action="store_false",
dest="coverrename", default=True, help=h["-c"])
parser.add_option("-p", "--noplaylists", action="store_false",
dest="playlists", default=True, help=h["-p"])
parser.add_option("-d", "--directory", metavar="DIR",
dest="dir", help=h["-d"])
(options, args) = parser.parse_args()
print options
print '-'*20
print args
if options.verbose:
pass
#jte=JTE(options)
if __name__ == '__main__':
main()
Code: Alles auswählen
tobsl@blechbuechse:~$ python torrentrename.py -h
Traceback (most recent call last):
File "torrentrename.py", line 102, in ?
main()
File "torrentrename.py", line 93, in main
(options, args) = parser.parse_args()
File "/usr/lib/python2.4/optparse.py", line 1280, in parse_args
stop = self._process_args(largs, rargs, values)
File "/usr/lib/python2.4/optparse.py", line 1324, in _process_args
self._process_short_opts(rargs, values)
File "/usr/lib/python2.4/optparse.py", line 1431, in _process_short_opts
option.process(opt, value, values, self)
File "/usr/lib/python2.4/optparse.py", line 712, in process
return self.take_action(
File "/usr/lib/python2.4/optparse.py", line 733, in take_action
parser.print_help()
File "/usr/lib/python2.4/optparse.py", line 1538, in print_help
file.write(self.format_help())
File "/usr/lib/python2.4/optparse.py", line 1526, in format_help
result.append(self.format_description(formatter) + "\n")
File "/usr/lib/python2.4/optparse.py", line 998, in format_description
return formatter.format_description(self.get_description())
File "/usr/lib/python2.4/optparse.py", line 1449, in get_description
return self.expand_prog_name(self.description)
File "/usr/lib/python2.4/optparse.py", line 1446, in expand_prog_name
return s.replace("%prog", self.get_prog_name())
AttributeError: 'tuple' object has no attribute 'replace'

Bitte klärt mich mal auf

LG Tobi