the windows interpreter

Shae Erisson shapr at uab.edu
Mon Jun 5 09:41:04 EDT 2000


Tim Gahnström wrote:
> 
> I downloaded and installed the python 1.5 for windows interpreter.
> I can use some pyton comands at the prompt like
> 
> >>> print "Hi"
> will causet the output
> Hi
> I can also create simple files with idle and run them with F5.
> But when I try to use an example program like
> 
> ----
> #! /usr/local/bin/python
> import sys
> if '-h' in sys.argv or '--help' in
> sys.argv or '--help' in sys.argv: print '''
> help.py--does nothing useful (yet)
> options: -h, -help, or --help-display this help
> Copyright (c) Jacek Artymiak, 2000 '''
>     sys.exit(0)
> else:
>     print 'I don't recognize this option' sys.exit(0)
> ---

the problem here is that you have a single line of python code that has
been continued on the next line, and the python interpreter doesn't know
that.
the only change I've made here is to add a single slash at the end of
the third line.
You should really read the python tutorial, it will make your life
easier.

if '-h' in sys.argv or '--help' in \
sys.argv or '--help' in sys.argv: print '''
help.py--does nothing useful (yet)
options: -h, -help, or --help-display this help
Copyright (c) Jacek Artymiak, 2000 '''

this could also be written as:
# assign the string to a variable to increase reabability
helpstring = '''
help.py--does nothing useful (yet)
options: -h, -help, or --help-display this help
Copyright (c) Jacek Artymiak, 2000 '''
# does the user want help?
if '-h' in sys.argv or '--help' in sys.argv or '--help' in sys.argv:
print helpstring

-- 
sHae mAtijs eRisson (sHae at wEbwitchEs.coM) gEnius fOr hIre
   bRing mE fIve sQuirrels aNd nO oNe wIll gEt hUrt
13:00pm up 1 season, 1 squirrel, load average: 1+1j 0.5+2j 0.2+0.5j



More information about the Python-list mailing list