Can someone fix my code?

bovinesoft at my-deja.com bovinesoft at my-deja.com
Sun Jan 30 23:42:25 EST 2000


I am a complete Python newbie and am trying to learn it as my first real
programming language (I have dabbled in C, Java, and Assembly, but never
really used them).  I am trying to write a program to get some practice,
but am getting errors when I try to run it.  If someone could take a
look at my code and tell me what is wrong with it, I would be greatly
appreciative.

import sys  # to use the exit() function

def ssi_or_exit():
   sorx = raw_input("Would you like to generate HTML <g> or exit <x>? ")
   if sorx == "g":  # if they want to generate a web page
      ssi()
   elif sorx == "x":  # if they want to exit
      sys.exit("Thank you for using Bovine No Server SSI!")
   else:
      ssi_or_exit() # try it again

def ssi():
   body_path = raw_input("Please type the path of the body section: ")
   body = open(body_path, "w")  # open the text of the web page body
   temp_path = raw_input("Please type the path of the HTML template: ")
   temp = open(temp_path, "r")  # open the HTML template
   temp2 = temp.readlines()
   where_temp = raw_input("Put the template before <b> or after <a> the
body? ")
   if where_temp == "b":  #around here is where my trouble starts
      for line in temp2:
         body.write(line)
      for line in body:
         body.write(line)
   else:
      for line in body:
         body.write(line)
      for line in temp2:
         body.write(line)
   body.close()
   temp.close()
   ssi_or_exit()

ssi_or_exit()


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list