required options

Thorsten Kampe <[email protected]> Thu, 9 Sep 2004 09:01:35 +0200
Newsgroups gmane.comp.python.optik.user
Message-ID <[email protected]>
The manual states that users often want "required (mandatory) options"
which is contradictory in itself. The manual suggests using positional
arguments instead.

I think this is some kind of misunderstanding. Positional arguments
are often not usable because only the position makes the argument the
source or the destination for example. It's not always as simple and
obvious as with "cp" (for instance I always get it wrong with "ln -s
TARGET LINK_NAME").

So what people actually want aren't "required options" but "named,
non-positional arguments" (something like "ln -s --target TARGET
--link-name LINK_NAME").

Python itself has a solution to this common problem for functions.

def func(arg1 = None, arg2 = None, arg3 = None):
    pass
	
You can call it with
func(myarg1, myarg2, myarg3)

if you want and remember all the positions. But you can also call it
with

func(arg3 = myarg3, arg1 = myarg1, arg2 = myarg2)

which is even better to remember.

This seems to be "non GNU" but also very pythonic. Does Optik support
or at least see the necessity for this problem that many people have?


Thorsten



-------------------------------------------------------
This SF.Net email is sponsored by BEA Weblogic Workshop
FREE Java Enterprise J2EE developer tools!
Get your free copy of BEA WebLogic Workshop 8.1 today.
http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click