由于某种原因,我无法使用Python打开HTML Customized页面

时间:2013-12-08 21:09:26

标签: python html html5 operating-system converter

到目前为止,这是我的代码:

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()

HTML页面开放正常,但它说“无”!这是为什么?我已经多次检查过,似乎无法解决问题。你能帮助我吗?附:我需要很快修复我的错误;我必须尽快提交!

2 个答案:

答案 0 :(得分:1)

print不会返回任何内容,因此code = print(...)表示code始终为None

如果您希望print成为字符串,请移除对code的调用。您还需要使用其他方法来格式化字符串。基本+连接有效,或(更好)使用字符串格式:

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

docs中了解更多内容。

答案 1 :(得分:1)

您正在分配

print

to“code”(print返回None)。