Skip to content

Instantly share code, notes, and snippets.

@phith0n
Created January 27, 2016 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save phith0n/afe56234e3301435c3dd to your computer and use it in GitHub Desktop.
Save phith0n/afe56234e3301435c3dd to your computer and use it in GitHub Desktop.
class decorator
class Tx(object):
def __init__(self):
print("Tx:init")
self.something()
def something(self):
print("Tx:something")
def otherthing(self):
print("Tx:otherthing")
def __call__(self, func):
def wrapper(s, url_list):
url_list.append(4)
self.otherthing()
return func(s, url_list)
return wrapper
class v2(object):
@Tx()
def run(self, url_list):
print("v2:run")
print(url_list)
x = v2()
x.run([1, 2, 3])
#####
# OUTPUT
#
# Tx:init
# Tx:something
# Tx:otherthing
# v2:run
# [1, 2, 3, 4]
#
#####
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment