[英]IndentationError: expected an indented block
I have just started with python. 我刚刚开始使用python。 I was executing a simple program given in 'Dive into Python' by Mark Pilgrim in Ubuntu. 我在Ubuntu中执行Mark Pilgrim在'Dive into Python'中给出的一个简单程序。 The program is as follows: 该计划如下:
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)
But it is showing error as follows: 但它显示错误如下:
File "./1.py", line 3
Returns string."""
^
IndentationError: expected an indented block
I have tried few things like giving a space in front of return on line 3, then instead of space using a tab. 我尝试了一些东西,比如在第3行返回前面给出一个空格,然后使用制表符而不是空格。 Can anybody help me in finding out what the error is about, why it has came, etc. and also with some easy tutorials with which a can go ahead. 任何人都可以帮助我找出错误是什么,为什么它来了,等等,还有一些简单的教程,可以继续。
Thanks in advance.. 提前致谢..
Try it like this: 试试这样:
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)
BTW: Do you understand the structure? 顺便说一句:你了解结构吗? Function, if __name__=="__main__":
block etc.? 函数, if __name__=="__main__":
块等?
Why not read the Python documentation? 为什么不阅读Python文档? It might help. 它可能有所帮助。 ;) ;)
http://docs.python.org/2/reference/lexical_analysis.html#indentation http://docs.python.org/2/reference/lexical_analysis.html#indentation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.