Python"NoneType"错误
我想打印出不带零的清单,以使其更具可读性。
这段代码的一部分在While循环中。
选择 | 换行 | 行号
- import copy
- pieces = [ [1,2,3,4,5,6] , [0,0,0,0,0,0], [0,0,0,0,0,0] ]
- def formatt (formatt) :
- while 0 in formatt[1] :
- formatt[1].remove(0)
- while 0 in formatt[2] :
- formatt[2].remove(0)
- while 0 in formatt[0] :
- formatt[0].remove(0)
- print formatt
- #part in loop \/
- form = copy.deepcopy(pieces)
- formatt(form)
但是在循环运行一次之后,我收到了这个错误消息:
回溯(最近一次呼叫):
文件"C:\Documents and Settings\JOS\Desktop\Towers of Henoy.py",第68行,中
格式(表单)
文件"C:\Documents and Settings\JOS\Desktop\Towers of Henoy.py",第37行,格式
格式为[1]时为0:
TypeError:'NoneType'对象不可订阅
有人能帮忙吗?
-谢谢
马赫姆1