Polymoprhism question

2013-05-24 Thread RVic
I'm trying to figure out (or find an example) of polymorphism whereby I pass a 
commandline argument (a string) which comports to a class (in java, you would 
say that it comports to a given interface bu I don't know if there is such a 
thing in Python) then that class of that name, somehow gets intantiated from 
that string. This way, I can have similar classes, but have my program use 
various ones by simply changing the commandline argument.

Can anyone show me how this might be done in Python? Thanks.

-RVic
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Polymoprhism question

2013-05-24 Thread RVic
Thanks Steven,

Yes, I see Python isn't going to do this very well, from what I can understand.

Lets say I have a type of class, and this type of class will always have two 
methods, in() and out().

Here is, essentially, what I am trying to do, but I don't know if this will 
make sense to you or if it is really doable in Python:  #thanks, RVic

import sys
argv = sys.argv[1:] 
ClassIamInstantiating = argv
ClassIamInstantiating.in("something")
x = ClassIamInstantiating.out()
-- 
http://mail.python.org/mailman/listinfo/python-list


Cutting a deck of cards

2013-05-26 Thread RVic
Suppose I have a deck of cards, and I shuffle them

import random
cards = []
decks = 6
cards = list(range(13 * 4 * decks))
random.shuffle(cards)

So now I have an array of cards. I would like to cut these cards at some random 
point (between 1 and 13 * 4 * decks - 1, moving the lower half of that to the 
top half of the cards array.

For some reason, I can't see how this can be done (I know that it must be a 
simple line or two in Python, but I am really stuck here). Anyone have any 
direction they can give me on this? Thanks, RVic, python newbie

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Cutting a deck of cards

2013-05-26 Thread RVic
Ah, brilliant -- yes, this is so much more elegant in Python:

#now cut the cards
x = random.randrange(2,range(13 * 4 * decks))
cards = cards[x:]+cards[:x]
-- 
http://mail.python.org/mailman/listinfo/python-list