python 函数相关
2011-03-18 15:27
351 查看
[ 装饰器:]
#!/usr/bin/env/ python
from time import ctime
def tsfunc(func):
~ def wrappedFunc():
~ ~ print '[%s] %s() called' % ( ctime(), func.__name__)
~ ~ return func()
~ return wrappedFunc
@tsfunc
def foo():
~ pass
foo() #=> [Sun Mar 19 22:50:28 2006] foo() called
[ lambda: ]
def usuallyAdd(x,y=2) : return x + y
<=> lambda x,y=2 : x+y
[ global: ]
def foo():
~ bar = 200
~ print bar
bar = 100
print bar #=> 100
foo() #=> 200
print bar #=> 100
def foo2():
~ global bar
~ bar = 300
~ print bar
print bar #=> 100
foo2() #=> 300
print bar #=> 300
#!/usr/bin/env/ python
from time import ctime
def tsfunc(func):
~ def wrappedFunc():
~ ~ print '[%s] %s() called' % ( ctime(), func.__name__)
~ ~ return func()
~ return wrappedFunc
@tsfunc
def foo():
~ pass
foo() #=> [Sun Mar 19 22:50:28 2006] foo() called
[ lambda: ]
def usuallyAdd(x,y=2) : return x + y
<=> lambda x,y=2 : x+y
[ global: ]
def foo():
~ bar = 200
~ print bar
bar = 100
print bar #=> 100
foo() #=> 200
print bar #=> 100
def foo2():
~ global bar
~ bar = 300
~ print bar
print bar #=> 100
foo2() #=> 300
print bar #=> 300
相关文章推荐
- Python中的eval()、exec()及其相关函数
- Python 函数相关
- Python数据分析模块 | pandas做数据分析(三):统计相关函数
- python中常用检测字符串相关函数汇总
- python3 字符串操作相关函数
- C调用Python函数相关代码示例剖析
- Python多线程的创建,相关函数和守护线程的理解
- python:2:字符串基本用法及相关函数
- Python元组及相关函数
- python函数参数相关总结
- python中与序列相关的内建函数
- Python与序列相关的内建函数
- python函数相关
- Python 文件读取相关操作函数
- Python 学习日记第七篇 -- 函数相关
- [置顶] 【python 内建函数】python中函数相关的内建函数
- python相关函数
- Python的输入和raw_input()内建函数等以及相关运算符
- Python多线程的创建,相关函数和守护线程的理解
- python 内建函数详解及相关示例