-1

i am trying to generate a html checkbox within a python function. this is my code

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

but when i try to compile it , it is giving the syntax error: expected an intended block. please let me know how to solve this problem.

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 回答
1

错误消息的名称应该让您了解问题所在。

您没有正确缩进,因此您得到“syntaxError: expected an indented block ”。

此外,在 Python 中,行不以分号结尾,这不是 C#。

我建议阅读基本Python 指南和阅读Python 教程

于 2013-04-05T20:08:40.223 回答