[Tutor] Newbie College Student

TheSarge ssg.hilton at comcast.net
Sun Aug 5 18:59:16 CEST 2007

Hi All,

Been tasked with an assignment that is kicking my butt. We have been asked
to write a py utilizing cgi to ask for simplistic web form guestbook
information (name and email). I think I am lost on whether or not my actual
py script needs to link to a cgi script or if I can do it all in a py
script. It needs to log entries to a text file and everytime I think I have
it working I go to my text file and it remains empty. I don't know if I can
post my script code in here so if I can not then my apologies forthcoming.
Any help or advice is most appreciated.

py script:

import cgi, cgitb, os

temp = """
<form action=sample.cgi>
First Name: <input type=text name=fname><br>
Last Name: <input type=text name=lname><br>
Email:  <input type=text name=email><br>
<input type=submit>

path = 'c:\\file'
# Create instance of FieldStorage 
form = cgi.FieldStorage() 

# Get data from field 'name' 
fname = form.getvalue('fname') 

# Get data from field 'address' 
lname = form.getvalue('lname') 

# Get data from field 'email' 
email = form.getvalue('email')

if not os.path.isdir(path):
    e=open(path + '\\' + 'logbook.txt','a')
    e.write("%s#%s#%s\n" % (fname,lname,email))
print 'Done'

What am I doing wrong? Been working on this two weekends in a row and the
assignment is already late.


View this message in context: http://www.nabble.com/Newbie-College-Student-tf4220394.html#a12006185
Sent from the Python - tutor mailing list archive at Nabble.com.

More information about the Tutor mailing list