Created
October 18, 2011 19:23
-
-
Save goozbach/1296419 to your computer and use it in GitHub Desktop.
Inheritance/scope problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.sw[po] | |
*.pyc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
import cmd | |
class FooCmd(cmd.Cmd, object): | |
"""Foo command processor example.""" | |
def __init__(self, mytuple=(), **kwds): | |
super(FooCmd, self).__init__(**kwds) | |
self.mytuple = mytuple | |
def do_stuff(self, line): | |
"""Print stuff""" | |
print("stuff") | |
def do_args(self, line): | |
print(self.mytuple) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
import foocmd | |
mycmd = foocmd.FooCmd(mytuple=('one', 'two', 'three')) | |
mycmd.cmdloop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
from __future__ import print_function | |
class Foo(object): | |
def __init__(self, fooarg='foob', **kwds): | |
self.fooarg = fooarg | |
class Bar(Foo): | |
def __init__(self, bararg='barb', **kwds): | |
super(Bar, self).__init__(**kwds) | |
self.bararg = bararg | |
myobj = Bar(timmy='twotone') | |
print(myobj.fooarg) | |
print(myobj.bararg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment