2013-12-08 57 views
0

一个HTML页面定制这里是我到目前为止的代码:我无法打开使用Python由于某种原因

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页面被打开了罚款,但它说“没有”!这是为什么?我已经检查了好几次,似乎无法解决问题。你可以帮我吗?附:我需要很快修复我的错误;我必须尽快提交!

回答

1

要分配

print 

到 “代码”(打印返回None)。

+0

所以我删除打印元素? –

+0

In: code = print(“<!Doctype html> \ n \ ... remove”code =“ – mchfrnc

+0

Thanks!It works! –

1

print不返回任何东西,所以code = print(...)意味着code将永远是None

如果您希望code为字符串,请删除对print的呼叫。您还需要使用其他方法来格式化字符串。基本+串联作品,或(更好)使用字符串格式化:

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

docs阅读更多。

+0

那么我该怎么做? –

相关问题