in meiner Klasse 'Frame()' verwende ich eine Methode 'move()' zur Steuerung des Bildschirmcursors.
Code: Alles auswählen
def move(self, step):
'''Frame.move(step) -> (string, bool)
'step' must be positive (moving forward),
negative (moving backward) integer or
zero (get current position).
The first element of the returning tuple is a
cursor positioning control sequence for moving
the cursor forward if 'step' is a positive
integer, backward if 'step' is a negative integer
or leave the cursor on the current xy-values
if 'step' is zero or the new coordinates were
outside of the frame object.
The second element of the returning tuple indicates
whether the xy-values has changed (True) or not
(False).'''
new_y = step + self._y
if new_y < 1 or new_y > self.cols * self.rows:
new_y = self._y
changed = self._y != new_y
self._y = new_y
return controls.MOVE_XYx.format(self.x, self.y), changed
Code: Alles auswählen
move = frame.move(0)[0]
#oder
move, _ = frame.move(0)
Als Lösung fiele mir ein, der 'Frame()'-Klasse ein Attribut 'has_changed' zu spendieren, das ich jeweils auf 'True' oder 'False' setze.
Welche Möglichkeiten gäbe es noch, um so etwas 'schön' zu lösen?
mutetella