Как читать построчно и анализировать файл в 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'
Спасибо за вашу помощь.
Ввод.txt
2 --- 2 simulations
3 3 -- 3*3 map
.A. --map
AA.
A.A
2 2 --2*2 map
AA --map
.A
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 = 0
xyLine= f.readLines()
row = int(xyLine.split()[0])
col = int(xyLine.split()[1])
myMap = [[Spot() for j in range(col)] for i in range(row)]
## for-while
i = 0
while i < row:
myLine = cls.br.readLines()
## for-while
j = 0
while j < col:
if (myLine.charAt(j) == 'B'):
cls.myMap[i][j] = Spot(True)
else:
cls.myMap[i][j] = Spot(False)
j += 1
i += 1
Для Spot.py
Spot.py
class Spot(object):
isBunny = bool()
nextCycle = 0
UP = 0
RIGHT = 1
DOWN = 2
LEFT = 3
SLEEP = 4
def __init__(self, newIsBunny):
self.isBunny = newIsBunny
self.nextCycle = self.UP
s = Spot(7); s.isBunny = 'joe'- person pillmuncher   schedule 27.09.2012