Code: Alles auswählen
def move_handler(self, direction="DOWN"):
"""Generator: give member, new_position tuples and yield None, None tuples if an object is
going to collide on the next move."""
DIRECTIONS = { "LEFT" : -1, "RIGHT" : 1, "DOWN" : False }
new_positions = {}
superblock_leaving_field = False
do_not_freeze = True
for member in self.members[:]:
position_to_check = member.get_position()
try:
if not DIRECTIONS[direction]:
new_position = (position_to_check[0] - 1, \
position_to_check[1]) # Block is moving vertical
else:
new_position = (position_to_check[0], \
position_to_check[1] + DIRECTIONS[direction])
except KeyError:
raise PositionException("Given Direction to Move isnt \
'LEFT' nor 'RIGHT' nor 'DOWN'. Cannot move.")
*snip*
yield member, new_position
Das schmeißt bei mir keine exception im unittest, beim direkten aufrufen in idle bekomm ich nach nem next() bloß sofort StopIteration, aber nicht die eigentliche Exception...? Bei dem Testskript hier funktionierts allerdings:
Code: Alles auswählen
#!/usr/bin/python
# -*- coding: iso-8859-15 -*-
def foo_generator(foo="FALSE"):
BAR = { "FOO" : 1, "BAR" : 2, "SPAM" : 3 }
try:
yield BAR[foo]
except KeyError:
raise ValueError("Blablabla")
yield "dummy string"
foobar = foo_generator()
foobar.next()
OT: Gibts eigentlich ne vim steuerung fürn browser (FF) ? langsam nervt der standard modus beim sürfän ^_^
EDIT: Grad mal geschaut bei mozilla.com, gibts sogar: https://addons.mozilla.org/en-US/firefox/addon/4891
Mal schauen >_>