I can't open a HTML Customized page using Python for some reason

Here is my code so far:

import os

print("The Arkeyan Text to HTML Converter\n\n")

w = 1

while w == 1:
   var1 = input("\n\nWhat would you like the title of your page to be? ")
   var2 = input("\nCool! Okay, now what is the text you want inside the body? ")
   align = input("\nHow would you like this to be aligned? (center, right or left) ")
   background = input("\nFinally, what background colour would you like? (It has to be in RGB format). Press 9 for more info.")

   if background == "9":
      background = input("\nGo to http://www.w3schools.com/tags/ref_colorpicker.asp to get a colour value and enter it in here: ")
      print("\n\nAll done! Here is your personalised code:\n\n")
      code = print("<!Doctype html>\n\
      <html>\n\
      <head>\n\
            <title>",var1,"</title>\n\
      </head>\n\n\n\
      <body bgcolor=\"",background,"\">\n\
      <div align=\"",align,"\">\n\
      <h1>",var1,"</h1><br>\n\
      <p>",var2,"</p>\n\
      </div>\n\
      </body>\n\
      </html>")

      my_file = open("C:\output.html", "w")

      my_file.write(str(code))

      my_file.close()

      os.system("C:\\output.html")

      x = input("\n\nThank you for using this HTML convert tool. Would you like to generate another code? ")
      if x == "yes":
         print("\n\n==========UNDERGOING LOOP PROCESS==========\n")
      elif x == "no":
         print("\n\n==========BREAKING THE LOOP==========\n")
         w = 2
      else:
         print("I don't understand you. Self-destruct sequence initaiated...")
         exit()

   else:

      print("\n\nAll done! Here is your personalised code:\n\n")
      code = print("<!Doctype html>\n\
      <html>\n\
      <head>\n\
            <title>",var1,"</title>\n\
      </head>\n\n\n\
      <body bgcolor=\"",background,"\">\n\
      <div align=\"",align,"\">\n\
      <h1>",var1,"</h1><br>\n\
      <p>",var2,"</p>\n\
      </div>\n\
      </body>\n\
      </html>")

      my_file = open("C:\output.html", "w")

      my_file.write(str(code))

      my_file.close()

      os.system("C:\\output.html")

      x = input("\n\nThank you for using this HTML convert tool. Would you like to generate another code? ")
      if x == "yes":
         print("\n\n==========UNDERGOING LOOP PROCESS==========\n")
      elif x == "no":
         print("\n\n==========BREAKING THE LOOP==========\n")
         w = 2
      else:
         print("I don't understand you. Self-destruct sequence initaiated...")
         exit()

The HTML Page is opening up fine, but it says 'None'! Why is that? I have checked it several times, and can't seem to resolve the issue. Can you help me? P.S. I need my error fixed quite quickly; I have to submit it soon!

Answers


You are assigning

print

to "code" (print returns None).


print does not return anything, so code = print(...) means that code will always be None.

Remove the call to print if you want code to be a string. You will also need to use a different method to format your string. Basic + concatenation works, or (better) use string formatting:

'this is a {} string'.format('formatted')
#this is a formatted string

read more in the docs.


Need Your Help

MVC action not being called from grid

c# asp.net-mvc-3 telerik telerik-grid

I have an MVC3 app that uses a Telerik grid. I have the following action: