Beispiel #1
0
def example():
    class A(Mixin):
        classVar = 'classVar val'

        def method(self, arg='method 1 default arg'):
            return arg

        def method2(self, arg='meth 2 default arg'):
            return {'item1': arg}

        def method3(self, arg='meth 3 default'):
            return arg

    class B(A):
        classBvar = 'classBvar val'

    a = A()
    a.one = 'valueForOne'

    def function(whichOne='default'):
        values = {
            'default': 'default output',
            'one': 'output option one',
            'two': 'output option two'
        }
        return values[whichOne]

    a.dic = {
        'func': function,
        'method': a.method3,
        'item': 'itemval',
        'subDict': {
            'nestedMethod': a.method3
        }
    }
    b = 'this is local b'

    print(valueForKey(a.dic, 'subDict'))
    print(valueForName(a, 'dic.item'))
    print(valueForName(vars(), 'b'))
    print(valueForName(__builtins__, 'dir')())
    print(valueForName(vars(), 'a.classVar'))
    print(valueForName(vars(), 'a.dic.func', executeCallables=True))
    print(valueForName(vars(), 'a.method2.item1', executeCallables=True))
Beispiel #2
0
def example():
    class A(Mixin):
        classVar = 'classVar val'
        def method(self,arg='method 1 default arg'):
            return arg

        def method2(self, arg='meth 2 default arg'):
            return {'item1':arg}

        def method3(self, arg='meth 3 default'):
            return arg

    class B(A):
        classBvar = 'classBvar val'

    a = A()
    a.one = 'valueForOne'
    def function(whichOne='default'):
        values = {
            'default': 'default output',
            'one': 'output option one',
            'two': 'output option two'
            }
        return values[whichOne]

    a.dic = {
        'func': function,
        'method': a.method3,
        'item': 'itemval',
        'subDict': {'nestedMethod':a.method3}
        }
    b = 'this is local b'

    print(valueForKey(a.dic, 'subDict'))
    print(valueForName(a, 'dic.item'))
    print(valueForName(vars(), 'b'))
    print(valueForName(__builtins__, 'dir')())
    print(valueForName(vars(), 'a.classVar'))
    print(valueForName(vars(), 'a.dic.func', executeCallables=True))
    print(valueForName(vars(), 'a.method2.item1', executeCallables=True))
Beispiel #3
0
 def valueForKey(self, key):
     return valueForKey(self, key)
Beispiel #4
0
 def valueForKey(self, key):
     return valueForKey(self, key)