【Python-03】练习03-20170714

遇到的错误信息
一、IndentationError:expected an indented block
Eclipse中,执行也需要注意缩进。
第一次执行时,未对print进行缩进,报错:IndentationError:expected an indented block。
一句话 有冒号的下一行往往要缩进,该缩进就缩进
How to deal with IndentationError:

  1. Make sure your lines are indented properly, remembering that Python thinks that tab stops are every 8 columns. 2) Look for a missing colon on the line above, which is usually a for, if, else, while, try, or similar type of line. In general, if a line ends in a colon, the next line with code needs to be indented by some amount. – Mike DeSimone Oct 13 '10 at 4:03

二、
但sys.setdefaultencoding('utf-8')已经没有意义了,
因为python3 使用unicode了,不用再设utf-8了
三、Jython Error: SyntaxError: inconsistent dedent at line 12 column 4
错误原因:缩进 空格
python最具特色的就是使用缩进来表示代码块,不需要使用大括号({})。
缩进的空格数是可变的,但是同一个代码块的语句必须包含相同的缩进空格数。
Solution: Delete the extra space, and remember that if you want to use tabs it is best to set your editor if it is possible to use spaces for tab characters, this will save you many late nights debugging tab based indentation vs space based indentation in your jython scripts.

Another reason why it is important to use spaces and not tabs is because as you copy code fom AIX/Linux shells to Windows ie between different text editors they IDE/editing tools. The may disagree on tab width, and if you have mixed tab and spaces during your typing/pasting, you can get a miss match of indentations.

Keep to spaces and use 2 or 4, then you are going to be fine!

四、python3中用HTMLTestRunner.py报ImportError: No module named 'StringIO'参考网址:http://www.cnblogs.com/testyao/p/5658200.html
修改配置文件

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容