[英]IndentationError: expected an indented block
我刚刚开始使用python。 我在Ubuntu中执行Mark Pilgrim在'Dive into Python'中给出的一个简单程序。 该计划如下:
def buildConnectionString(params):
"""Build a connection string from a dictionary of parameters.
Returns string."""
return ";".join(["%s=%s" % (k, v) for k, v in params.items()])
if __name__ == "__main__":
myParams = {"server":"mpilgrim", \
"database":"master", \
"uid":"sa", \
"pwd":"secret" \
}
print buildConnectionString(myParams)
但它显示错误如下:
File "./1.py", line 3
Returns string."""
^
IndentationError: expected an indented block
我尝试了一些东西,比如在第3行返回前面给出一个空格,然后使用制表符而不是空格。 任何人都可以帮助我找出错误是什么,为什么它来了,等等,还有一些简单的教程,可以继续。
提前致谢..
试试这样:
def buildConnectionString(params):
"""Build a connection string from a dictionary of parameters.
Returns string."""
return ";".join(["%s=%s" % (k, v) for k, v in params.items()])
if __name__ == "__main__":
myParams = {"server":"mpilgrim", \
"database":"master", \
"uid":"sa", \
"pwd":"secret" \
}
print buildConnectionString(myParams)
顺便说一句:你了解结构吗? 函数, if __name__=="__main__":
块等?
为什么不阅读Python文档? 它可能有所帮助。 ;)
http://docs.python.org/2/reference/lexical_analysis.html#indentation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.