[Tutor] Dual interface app
Alan Gauld
alan.gauld at blueyonder.co.uk
Thu Aug 12 22:53:34 CEST 2004
> problems when I thought this out further. What if someone runs it
from a
> command line and forgets to add the arguments? The program will
check
> for command line arguments, then it will check the cgi form values
and
> assume it's being called from the web interface.
So put that check inside a try/except clause and if the cgi lookup
fails the except can either supply defaults or use raw_input to
prompt the user.
if len(sys.argv) == argCount:
args = sys.argv
else:
try:
args = getCGIvalues()
except ????: # whatever the cgi module raises...
args = raw_input('gimme the args ')
# now process args...
> Does anyone have any other ideas? Is there a way to detect if a
program
> is being called from the command line vs web without too much
voodoo?
Not sure what happens to __name__ when its a web app, but my guess
is its still __main__...
HTH,
Alan G
Author of the Learn to Program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld/tutor2/
More information about the Tutor
mailing list