Chinaunix首页 | 论坛 | 博客
  • 博客访问: 428744
  • 博文数量: 184
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 594
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-17 16:24
个人简介

我是一只小小鸟

文章分类

全部博文(184)

文章存档

2016年(1)

2015年(55)

2014年(127)

2013年(1)

分类: Python/Ruby

2014-05-08 17:58:32

问题1:
执行python时提示:

SyntaxError: Non-ASCII character '\xef' in file ip on line 23, but no encoding declared; see for details
原因:脚本中出现了非ASCII码以外的其他字符
解决:
如果在python中出现了非ASCII码以外的其他字符,需要在代码的开头声明字符格式。具体声明字符的方法有三种:
         # coding=

    or (using formats recognized by popular editors)

          #!/usr/bin/python
          # -*- coding: -*-

    or

          #!/usr/bin/python
          # vim: set fileencoding= :


此处采用:
#!/usr/bin/python
#-*-coding:utf-8-*-
即可解决。
问题2:
执行script时提示:
IndentationError: expected an indented block
分析:
     Python是一款对缩进非常敏感的语言。最常见的情况是tab和空格的混用会导致错误,或者缩进不对,而这是用肉眼无法分别的。上面这种情况就是由于缩进不同而造成的。
解决:
打开相应文件查找错误提示行,更改缩进,建议用Tab
阅读(623) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~