Я могу ввести следующий код в терминале, и он работает:
for i in range(5):
print(i)
И он напечатает:
0
1
2
3
4
как и ожидалось. Тем не менее, я попытался написать скрипт, который делает похожую вещь:
print(current_chunk.data)
read_chunk(file, current_chunk)
numVerts, numFaces, numEdges = current_chunk.data
print(current_chunk.data)
print(numVerts)
for vertex in range(numVerts):
print("Hello World")
current_chunk.data получается из следующего метода:
def read_chunk(file, chunk):
line = file.readline()
while line.startswith('#'):
line = file.readline()
chunk.data = line.split()
Выход для этого:
['OFF']
['490', '518', '0']
490
Traceback (most recent call last):
File "/home/leif/src/install/linux2/.blender/scripts/io/import_scene_off.py", line 88, in execute
load_off(self.properties.path, context)
File "/home/leif/src/install/linux2/.blender/scripts/io/import_scene_off.py", line 68, in load_off
for vertex in range(numVerts):
TypeError: 'str' object cannot be interpreted as an integer
Итак, почему он не выплевывает Hello World 490 раз? Или 490 считается строкой?
Я открыл файл так:
def load_off(filename, context):
file = open(filename, 'r')