Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

FOIC question, EXPERT LEVEL How to alter mro in runtime?

Name: Anonymous 2015-05-03 22:45

Impl(object):
def __init__(self):
pass
def shit(self):
pass

StdoutImpl(Impl):
def shit(self):
print("A shit has been shat.")

StderrImpl(Impl):
def shit(self):
__import__("sys").stderr.write("A shit has been shat to stderr.\n")

class MyApplicationg(object):
def __init__(self, implname):
if implname == "stderr":
magic(StderrImpl, self)
else:
magic(StdoutImpl, self)

def magic(cls, object):
# ?????????????
# ????????????????
# ?????????
pass

Name: Anonymous 2015-05-03 22:48

Oh shit I forgot, I want MyApplication to call self.shit() in its methods.

Name: Anonymous 2015-05-03 22:50

def magic(cls, object_):
instance = cls()
for k in dir(instance):
object_.setattr(k, getattr(instance, k))

Name: Anonymous 2015-05-03 22:56

>>4
OK, I shall get out now.

Name: Anonymous 2015-05-04 13:58

http://stackoverflow.com/questions/20822850/change-python-mro-at-runtime
.-=-. .--.
__ .' '. / " )
_ .' '. / .-. \ / .-'\
( \ / .-. \ / / \ \ / / ^
\ `-` / \ `-' / \ `-` /
/prog/`-.-` '.____.' `.____.'

Name: Anonymous 2015-05-04 14:31

>>1
>>2
>>3
>>4
>>5
>>6
If it ain't LISP, it's crap.

Name: Anonymous 2015-05-04 17:16

>>7
Protip: Use a hyphen to reference many continuous posts at once (>>1-6). Use commas to reference non-continuous posts (>>1,3,5).

You can mix these, too: >>1-3,5-7,9

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List