Re: --help option: sys.exit or return?

[email protected] Wed, 20 Oct 2004 11:28:26 +1000
Newsgroups gmane.comp.python.optik.user
Organization Lingfo Pty Ltd
Message-ID <41764BDA.30665.1335473@localhost>
> 
> For me, 100% of scripts that use Optik are of the "parse command-line
> args and exit on error or help/version query".  I don't want to write
> duplicate logic in every single one of those scripts to handle the
> "exit on error or help/version query" bit -- that would get tiresome
> very quickly.  So I have Optik do it for me.
> 
> I suspect that at least 90% of scripts in the wild that use Optik are
> of the same pattern.  Optik 1.5 has a minor refactoring where I pulled
> out an exit() method that should address the small minority of cases
> where exiting immediately is not the right thing to do.  Case closed,
> as far as I am concerned.

I don't understand the OP's problem or what the use case is.

You have a function to which you want a command line interface.

def foofunc(filename='', sep='csv', nheaders=0):
    etc etc

so with optik you can set up the "name==main" part of the module so that you can type 
something like:
    python mymodule.py -f somefile.txt -s tab -n 1
on the command line and the effect is this:

   mymodule.foofunc('somefile.txt', 'tab', 1)

If you want to call your foofunc from within the interpreter, you just type that in yourself, 
don't you? Why bother going through optik?

Am I missing something?