def echo3():
	lib_lib.mylib().test(123)
Пример #2
0
def echo3():
    lib_lib.mylib().test(123)
from lib import echo, echo3, echoX

echo()

echo3()

def _echo3(self, data):
	print self, data, 'after override class method'

# override instance method!
lib_lib.mylib.test = lambda self, data: _echo3(self, data)
echo3()

# test import as local function
from lib_lib import mylib
mylib().test(789)  # as same as after override instance method

# override loggging method
import logging
from logging import warn as _warn

def _warn_(msg):
	print '-'*50
	print 'Do something before invoke info()'
	h = _warn(msg)
	print '-'*50
	return h

logging.warn = lambda msg: _warn_(msg)
logging.warn("test after override logging.warn.")
# import pdb; pdb.set_trace()
echo()

echo3()


def _echo3(self, data):
    print self, data, 'after override class method'


# override instance method!
lib_lib.mylib.test = lambda self, data: _echo3(self, data)
echo3()

# test import as local function
from lib_lib import mylib
mylib().test(789)  # as same as after override instance method

# override loggging method
import logging
from logging import warn as _warn


def _warn_(msg):
    print '-' * 50
    print 'Do something before invoke info()'
    h = _warn(msg)
    print '-' * 50
    return h


logging.warn = lambda msg: _warn_(msg)