[Tutor] passing unknown no of arguments

Senthil Kumaran orsenthil at gmail.com
Thu Feb 5 09:57:01 CET 2009


On Thu, Feb 5, 2009 at 1:37 PM, amit sethi <amit.pureenergy at gmail.com> wrote:
> How do you pass arguments of unknown no. of arguments to a function.

You use * operator ( indirection) in the function definition for
arguments and you pass the variable number of number arguments as a
list.
For e.g.

>>> def foo(*args):
...     print args
...
>>> foo(1,2,3,4,5,6)
(1, 2, 3, 4, 5, 6)
>>> foo(1,2,3)
(1, 2, 3)
>>>

> Also how can i run my python scripts in a web browser.

What you are asking for is Python CGI programming.
Look out for chapters for Alan's book. I think he has covered from the basics.

Or just start here:
pytute.blogspot.com/2007/05/python-cgi-howto.html

You will write a simple script like
#!/usr/bin/env python
print "Content-Type: text/html\n"
print "Hello, World"

Give permissions chmod +rw to the script
and put it in your web-server's cgi-bin/ directory and invoke the python file.
The result will be displayed in the browser.


-- 
Senthil
http://uthcode.sarovar.org


More information about the Tutor mailing list