[Tutor] Running a python script from another python script
M.Sinan ORUN
sinan at orun.org
Thu Mar 24 19:47:41 CET 2005
Hello,
I am a newbee in python and trying to make a small script for my school
project . I try to run a python cgi script from another phyton script
as a result of an action . What is the neccesary command for this action
and is there a special class have to be imported for this command.
below i am giving so for what i have writen and what am i trying to do.
Thant you for your help
this is my first script for a basic log in action. i want to run the
second script from this script as a result of login action
##### index.cgi##### login script
#!/usr/bin/python
import cgi
print "Content-Type: text/html\n\n"
# Define function to generate HTML form.
def generate_form():
print "<HTML>\n"
print "<HEAD>\n"
print "\t<TITLE>Info Form</TITLE>\n"
print "</HEAD>\n"
print "<BODY BGCOLOR = white>\n"
print "\t<H3>Please, enter your UserName and Password.</H3>\n"
print "\t<TABLE BORDER = 0>\n"
print "\t\t<FORM METHOD = post ACTION = \"index.cgi\">\n"
print "\t\t<TR><TH>UserName:</TH><TD><INPUT type = text name =
\"UserName\"></TD><TR>\n"
print "\t\t<TR><TH>Password:</TH><TD><INPUT type = password name = \
\"Password\"></TD></TR>\n"
print "\t</TABLE>\n"
print "\t<INPUT TYPE = hidden NAME = \"action\" VALUE = \"display\">\n"
print "\t<INPUT TYPE = submit VALUE = \"Enter\">\n"
print "\t</FORM>\n"
print "</BODY>\n"
print "</HTML>\n"
# Define main function.
def main():
form = cgi.FieldStorage()
if (form.has_key("action") and form.has_key("UserName") and
form.has_key("Password")):
if (form["UserName"].value == "sinan" and form["Password"].value== "666"):
print "Welcome Boss !!"
#### here i need a command to move on my second script
(index1.cgi)#########
else:
print " You are not recognized !!"
generate_form()
else:
print " You are not recognized !!"
generate_form()
main()
########## index1.cgi ############# this is my second script whish has
to be runned from the first script
#### as a result of login action#####
#!/usr/bin/python
import cgi
print "Content-Type: text/html\n\n"
# Define function to generate HTML form.
#menulist
def menulist():
print "<HTML>\n"
print "<HEAD>\n"
print "\t<TITLE>Menu List</TITLE>\n"
print "</HEAD>\n"
print "<BODY BGCOLOR = white>\n"
print "\t<H3>Please choice a operation.</H3>\n"
print "<FORM METHOD = post ACTION = \"index1.cgi\">\n"
print "<select name=\"operations\">"
print "<option value=\"People\">People"
print "<option value=\"Lessons\">Lessons"
print "<option value=\"Projects\">Projects"
print "</SELECT>"
print "<BR>"
print "<INPUT TYPE=\"reset\">"
print "<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Submit\">"
print "</FORM>"
print "</BODY>\n"
print "</HTML>\n"
def Menu():
form = cgi.FieldStorage()
if (form.has_key("operations")):
if (form["operations"].value == "People"):
print "people menu"
elif (form["operations"].value == "Lessons"):
print "lesson menu"
elif (form["operations"].value == "Projects"):
print "project menu"
else:
print "error"
else:
menulist()
Menu()
More information about the Tutor
mailing list