如何解决参数“无法解析没有顺序的参数”的错误?

2024-10-17 08:19:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我认为问题在于:

    result = CoordinateRow([])

当我调试它时,我得到一个返回None的错误

错误:

Traceback (most recent call last):
   line 60, in <module>
    interlaced_rows = get_interlace_rows(splits_file)
   line 49, in get_interlace_rows
    previous_row = previous_row.interlace(row)
AttributeError: 'NoneType' object has no attribute 'interlace'

取消缩进返回结果后出现新错误(在类CoordinaterRow中):

Traceback (most recent call last):
   line 29, in __getattr__
    return self[item]
  line 25, in __getitem__
    return self._dict[item]
KeyError: 'calculate_new_coord'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
   line 59, in <module>
    get_new_coordinates(interlaced_rows)
  line 54, in get_new_coordinates
    new_coordinates = current_coordinates.calculate_new_coord()
  line 32, in __getattr__
    "'{}' object has no attribute '{}'".format(type(self).__name__, item)
AttributeError: 'Coordinate' object has no attribute 'calculate_new_coord'

Tags: inmostnewgetobject错误linecall
1条回答
网友
1楼 · 发布于 2024-10-17 08:19:55

从坐标pypi页面:

They can be instantiated in any of the ways a dict can (from another Mapping, a sequence of pairs, some keyword arguments, or a mixture of the above).

例如:

Coordinate(x=1, y=2)

只需在get_new_coordinates函数中更改这一行:

current_coordinates = Coordinate(int(coordinate[0]), int(coordinate[2]))

致:

current_coordinates = Coordinate(x=int(coordinate[0]), y=int(coordinate[2]))

但是,在此之后,您的代码会得到一个AttributeError: 'Coordinate' object has no attribute 'calculate_new_coord',因为您使用的calculate_new_coord方法在Cordinate类中不存在

编辑:更改问题后,显示不需要坐标模块。只需删除,然后使用您自己的坐标类。在课堂上,将此行更改回原来的位置:

current_coordinates = Coordinate(int(coordinate[0]), int(coordinate[2]))

这样,我就得到了预期的输出:

6,4
6,5
10,8
8,8
8,6
7,5
7,3
7,4
5,5
4,2
9,7
10,6
5,3

但是,如果需要使用坐标模块,只需执行以下操作:

def get_new_coordinates(interlace_rows):
    for coordinate in interlace_rows.row:
        current_coordinates = Coordinate(order='xy', x=int(coordinate[0]), y=int(coordinate[2]))
        new_coordinates = current_coordinates + Coordinate(order='xy', x=1, y=0)
        print('%d,%d' % (new_coordinates['x'], new_coordinates['y']))

在这种情况下,需要删除或重命名坐标类

相关问题 更多 >