-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from eastlakeside/issue28_add_pure_code
纯可执行代码的说明,以及同步了 #33 的代码修复
- Loading branch information
Showing
4 changed files
with
30 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
示例代码说明 | ||
======= | ||
> 此目录中为可执行的纯代码,方便读者自动动手执行,加深理解,或者用于项目中 | ||
## Python版本兼容性 | ||
- 书文中夹带的代码: 保证兼容Python 2/3,均可运行 | ||
- 此处的代码: 为了更好地方便读者直接使用,做了专门针对2.7版本的代码,3+版本的代码暂未实现,欢迎PR |