[Tutor] sorting variables
Evert Rol
evert.rol at gmail.com
Thu Nov 1 10:52:40 CET 2007
> i was thinking of doing something like
>
> objSprites = pygame.sprite.OrderedUpdates((var1,
> var2, var3).sort)
>
> but i don't think thats gunna work
It won't indeed, because of 3 things:
1. you're trying to sort a tuple. Tuples don't have a sort() method,
use a list instead
2. sort doesn't return! (well, it returns None in a way.) It's a
thing that has caught me once too often. You'll need to do the
sorting before using the sorted list again
3. you cannot insert a list (or tuple) as argument to a function and
expect it to be automatically expanded to several arguments. Use the
'*' in front of the list to expand (tuple won't work).
So what should work is:
args = [var1, var2, var3]
args.sort()
objSprites = pygame.sprite.OrderedUpdates(*args)
It's a few more lines, but that's the way it works. Hope that that
helps.
Cheers,
Evert
More information about the Tutor
mailing list