-1

Python 関数内で html チェックボックスを生成しようとしています。これは私のコードです

import HTML 
def CreateEvent(str):
"This prints a passed string into this function"
   print str;
   return;

CreateEvent ('''
content-type: text/html 

 <html> 
 <head> 
 <title> the list of all possible events that can be notified by our system </title> 
 </head> 
 <body> 
<form>
<input type="checkbox" name="tsunami" value="tsunami">tsunami<br>
<input type="checkbox" name="earthquake" value="earthquake">earthquake<br>
<input type="checkbox" name="volcano" value="volcano">volcano<br>
<input type="checkbox" name="hurricane" value="hurricane">hurricane<br>
<input type="checkbox" name="sinkholes" value="sinkholes">sinkholes<br>
<input type="checkbox" name="tornado" value="tornado">tornado<br>
<input type="checkbox" name="landslide" value="landslide">landslide<br>
<input type="checkbox" name="downburst" value="downburst">downburst<br>
</form>

<input type="submit" value="Submit">
</body>
</html>
''')

しかし、コンパイルしようとすると、構文エラーが発生します:意図したブロックが必要です。この問題を解決する方法を教えてください。

4

3 に答える 3

2

コメントにインデントはありません。

注: コメントは"""ありません"

import HTML 
def CreateEvent(str):
    """This prints a passed string into this function"""
    #^ Indentation space needed here - Also docstrings are represented with """ and not "
    print str
    #Good practice to have 4 spaces as indentation.
    return
    #     ^ No need of ;

pep8Python ライブラリをインストールして、

pep8 <filename>.py

問題があれば修正します

于 2013-04-05T20:13:52.300 に答える
1

適切にインデントする必要があります。

def CreateEvent(str):
    "This prints a passed string into this function"
    ...

...そして、これはPEP8に従って三重引用符で囲まれた文字列でなければなりません

...そして行末にセミコロンを置かないでください

于 2013-04-05T20:03:20.950 に答える