Created
August 21, 2017 06:15
-
-
Save laixintao/121ef17e2ca460fb9091fcac171d0da8 to your computer and use it in GitHub Desktop.
python的re在函数中编译之后,退出函数并不会立即被回收,下次会使用同样的re
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
# -*- coding: utf-8 -*- | |
import re | |
def clean(string): | |
re_strip = re.compile(r'(^\s+)|([\s::]+$)') | |
print id(re_strip) | |
result = re_strip.sub('', string) | |
return result | |
print clean(" test ,...") | |
print clean("\t test ,...") | |
# output | |
4503430416 | |
test ,... | |
4503430416 | |
test ,... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment