免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1501 | 回复: 4
打印 上一主题 下一主题

python环境运行异常 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-07-18 09:17 |只看该作者 |倒序浏览
代码:
def foo():
    "this is a doc string."
    return true

在命令行环境第二行完成后,就报错:

root@bogon:/opt# python
Python 2.6.6 (r266:84292, Dec 27 2010, 00:02:40)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def foo():
... "this is a doc string."  File "<stdin>", line 2
    "this is a doc string."
                          ^
IndentationError: expected an indented block
>>>

在ipython环境下输入完全正确。

请明白原由的朋友给个指导,谢谢!

论坛徽章:
0
2 [报告]
发表于 2012-07-18 09:24 |只看该作者
需要有缩进

论坛徽章:
0
3 [报告]
发表于 2012-07-18 09:30 |只看该作者
谢谢!这个问题不是缩进的问题,您可以在linux命令行环境测试下。

论坛徽章:
0
4 [报告]
发表于 2012-07-18 09:38 |只看该作者
测试了,是缩进问题:
  1. [root@fruit ~]# python
  2. Python 2.6.6 (r266:84292, Jun 18 2012, 14:10:23)
  3. [GCC 4.4.6 20110731 (Red Hat 4.4.6-3)] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> def foo():
  6. ... "this is a doc string."
  7.   File "<stdin>", line 2
  8.     "this is a doc string."
  9.                           ^
  10. IndentationError: expected an indented block
  11. >>> def foo():
  12. ...     "this is a doc string."
  13. ...     return true
  14. ...
  15. >>>
复制代码

论坛徽章:
0
5 [报告]
发表于 2012-07-18 09:47 |只看该作者
奥,明白了。谢谢!
命令行也要保持缩进,非常感谢!
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP