[getopt-sig] The bake-off

Greg Ward gward@python.net
Thu, 30 May 2002 11:49:20 -0400


On 30 May 2002, rsc@plan9.bell-labs.com said:
> The thing is that Python programmers already know
> how to deal with lists.  So if you tell them that the options
> being parsed are just a list, then they can figure out how
> to do 
> 	optionlist.append(foo)
> for themselves rather than need to learn add_option.

But add_option() is *not* a synonym for append().  It groks keyword args
nicely:

  parser.add_option("-n", type="int", dest="num_things")

to do that with the list interface, you need to explicitly construct an
Option object:

  options = 
  parser = OptionParser(option_list=[
      ...,
      make_option("-n", type="int", dest="num_things"),
      ...])

(make_option() is an alias for Option in Optik 1.3, since I had vague
ideas about splitting the Option class up into multiple subclasses.)

I now think the latter interface is clunkier.  I'm torn about whethere
there should be More Than One Way To Do It.  Harri's right though -- if
TIMTOWTODI, then both ways should be documented.  Grumble.

        Greg
-- 
Greg Ward - Unix geek                                   gward@python.net
http://starship.python.net/~gward/
If you're not part of the solution, you're part of the precipitate.