小编Mik*_*ike的帖子

TypeError:'bool'对象不可调用

我是python的新手.我收到了一个错误

while not cls.isFilled(row,col,myMap):
TypeError: 'bool' object is not callable
Run Code Online (Sandbox Code Playgroud)

你能指导一下如何解决这个问题吗?第一个"if"检查没问题,但"while not"有这个错误.

def main(cls, args):
        ...
        if cls.isFilled(row,col,myMap):
            numCycles = 0

        while not cls.isFilled(row,col,myMap):
            numCycles += 1


def isFilled(cls,row,col,myMap):
        cls.isFilled = True
        ## for-while
        i = 0
        while i < row:
            ## for-while
            j = 0
            while j < col:
                if not myMap[i][j].getIsActive():
                    cls.isFilled = False
                j += 1
            i += 1
        return cls.isFilled
Run Code Online (Sandbox Code Playgroud)

python

17
推荐指数
1
解决办法
9万
查看次数

如何逐行阅读并解析python中的文件?

如何逐行阅读并解析python中的文件?

我是python的新手.

第一行输入是模拟的数量.下一行是行数(x),后跟一个空格,后跟列数(y).下一组y行将具有x个字符,其中一个句点('.')表示空格,单个国会大厦"A"表示起始代理.

我的代码出错了

Traceback (most recent call last):
    numSims = int (line)
TypeError: int() argument must be a string or a number, not 'list'
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

INPUT.TXT

2   --- 2 simulations
3 3  -- 3*3 map
.A.  --map
AA.
A.A
2 2  --2*2 map
AA  --map
.A
Run Code Online (Sandbox Code Playgroud)
def main(cls, args):
    numSims = 0
    path = os.path.expanduser('~/Desktop/input.txt') 
    f = open(path) 
    line = f.readlines() 
    numSims = int (line)
    print numSims
    k=0
    while k < numSims:
        minPerCycle = 1
        row = 0
        col …
Run Code Online (Sandbox Code Playgroud)

python parsing readline

2
推荐指数
1
解决办法
2531
查看次数

标签 统计

python ×2

parsing ×1

readline ×1