BlueHat-GURU/python-blackjack — pull request #1 by crashfrog (2014-07-23 13:56:22+00:00)
Title: monkeypatching demo

Hi Bluehat, here's a demo of what I was talking about, and I'll just go over the meaty bits:

line 1: the interpreter will only import a module once, so I need to import it before you do. the easiest way to do that is make sure that it's my code that runs yours.
line 3: we need to save a pointer to the "real" random.shuffle function, because we're going to build a wrapper around it.
line 5: star-syntax means we can collect "extra" arguments and pass them along without knowing what they are; this is an easy way to maintain compatibility with the original random.shuffle function signature.
line 7: pass the shuffle call along.
line 8: our actual cheat - print the next ten cards from the back of the list. that should give us an edge on the house!
line 10: poke our function into the random module. Now the casino works for us!
line 12, 13: import and run the casino.