zoukankan      html  css  js  c++  java
  • Python方法

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    #
    #  static_method.py
    #  
    #  Copyright 2013 xx <xx@ubuntu>
    #  
    class foo():
    	def __init__(self):
    		print 'this is init'
    		
    	@staticmethod		#声明静态方法
    	def bar():
    		print 'this is foo.bar()'
    
    def decorator1(func):
    	def wrap1():
    		print 'this is wrap 1 begin'
    		func()
    		print 'this is wrap 1 end'
    	return wrap1
    		
    def decorator2(func):
    	def wrap1():
    		print 'this is wrap 2 begin'
    		func()
    		print 'this is wrap 2 end'
    	return wrap1
    
    # python装饰方法,类似java aop
    # <=> decorator2(decorator1(fun1))
    @decorator2
    @decorator1
    def fun1():
    	print 'this is fun1()'
    
    	
    def main():
    	foo.bar()		#类调用
    	print '*' * 20
    	foo().bar()		#对象调用
    	print '*' * 20
    	fun1()
    	
    	return 0
    
    if __name__ == '__main__':
    	main()
    
  • 相关阅读:
    灌注和宝石性道法价比分析
    bzoj1912
    bzoj3504
    poj3580
    bzoj1251
    bzoj3223
    bzoj1212
    bzoj3790
    记一次惨痛的比赛
    bzoj2734
  • 原文地址:https://www.cnblogs.com/wucg/p/3041507.html
Copyright © 2011-2022 走看看