arguments from the prompt

joe at localhost.localdomain joe at localhost.localdomain
Mon Feb 7 23:02:37 EST 2000


On Sun, 06 Feb 2000 22:57:29 GMT, Fredrik Lundh <effbot at telia.com> wrote:
>joe at localhost.localdomain wrote:
>> how do I write a python script to recive arguments from the
>> command prompt?
>
>you import the sys module, and read up on
>sys.argv in the manual?
>
>(hint: sys.argv contains a list of all command
>line arguments passed to the program. argv[0]
>is the name of the program itself).
>
>if you want to parse options in a standard
>fashion, you can use the getopt module.  see
>the docs for details.
>
></F>
>
it says NameError: sys
Here is the program I am writing (to cheat on my algebra homework when 
they want me to make tables of quadratic functions.)
I want to be able to type:
./prog a b c min max inc
and have it print a pretty table

#!/usr/bin/python
from sys import argv

a=sys.argv[1]
b=sys.argv[2]
c=sys.argv[3]
start=sys.argv[4]
end=sys.argv[5]
inc=sys.argv[6]



x=start
for x in range(start,end,inc):
  y=a*x**2+b*x+c
  print x,": ",y



More information about the Python-list mailing list