【Python-03】練習03-20170714

weixin_34320159發表於2017-07-15

遇到的錯誤資訊
一、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
修改配置檔案