Skip to content

Commit

Permalink
Merge pull request #35 from eastlakeside/issue28_add_pure_code
Browse files Browse the repository at this point in the history
纯可执行代码的说明,以及同步了 #33 的代码修复
  • Loading branch information
suqi committed Apr 7, 2016
2 parents 3f950df + 8e05024 commit bdf8b4b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ Python进阶
- Github快速阅读任一章节:[进入目录](https://github.com/eastlakeside/interpy-zh/blob/master/SUMMARY.md)
- Gitbook完整顺序地阅读:[进入Gitbook](https://eastlakeside.gitbooks.io/interpy-zh/content/)
- 本地或kindle上阅读:[下载pdf/epub/mobi](https://github.com/eastlakeside/interpy-zh/releases)
- 国内镜像:访问速度更快,不过更新可能稍微滞后:[v2ex热心网友kingmo888提供](http://lizenghai.com/doc/Intermediate_Python_CN/)

- 国内镜像:访问速度更快,更新可能滞后:[kingmo888@v2ex提供](http://lizenghai.com/doc/Intermediate_Python_CN/)
- 纯代码阅读和演示:[进入code目录](https://github.com/eastlakeside/interpy-zh/tree/master/code/)

# 前言

Expand Down
2 changes: 2 additions & 0 deletions code/2.7/7_decorators_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def wrapped_function(*args, **kwargs):

with open(logfile, 'a') as opened_file:
opened_file.write(log_string + '\n')

return func(*args, **kwargs)
return wrapped_function
return logging_decorator

Expand Down
29 changes: 19 additions & 10 deletions code/2.7/7_decorators_class.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
from functools import wraps

class logit(object):
def __init__(self, logfile='out.log'):
self.logfile = logfile
def __call__(self, func):
log_string = func.__name__ + ' was called'
print log_string
def __init__(self, logfile='out.log'):
self.logfile = logfile

with open(self.logfile, 'a') as opened_file:
opened_file.write(log_string + '\n')
self.notify
def notify(self):
pass
def __call__(self, func):
@wraps(func)
def wrapped_function(*args, **kwargs):
log_string = func.__name__ + " was called"
print(log_string)

with open(self.logfile, 'a') as opened_file:
opened_file.write(log_string + '\n')
self.notify()

return func(*args, **kwargs)
return wrapped_function

def notify(self):
pass

class email_logit(logit):
def __init__(self, email='[email protected]', *args, **kwargs):
Expand Down
7 changes: 7 additions & 0 deletions code/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
示例代码说明
=======
> 此目录中为可执行的纯代码,方便读者自动动手执行,加深理解,或者用于项目中
## Python版本兼容性
- 书文中夹带的代码: 保证兼容Python 2/3,均可运行
- 此处的代码: 为了更好地方便读者直接使用,做了专门针对2.7版本的代码,3+版本的代码暂未实现,欢迎PR

0 comments on commit bdf8b4b

Please sign in to comment.