- unimport a module
importsysimportAA.BB as CC;del sys.modules["AA.BB"]
- function trace
def flog(format, *params):print("mytest:"+format %params)defmyfunction(a, b)
flog("%s %s", sys._getframe().f_code.co_name, locals())pass
- replace '\' with '/':
full_path = os.path.realpath(__file__);
full_path = full_path.replace('\\','/')
http://www.pythonscripting.com
A Brief Introduction to Python with Only One Figure
20 of the Best Free Python Books
1. Think Python
2. Invent Your Own Computer Games with Python
3. Snake Wrangling for Kids
4. Learn Python the Hard Way, 2nd Edition
5. Natural Language Processing with Python
6. Building Skills in Python
7. Dive into Python
8. Text Processing in Python
9. The Standard Python Library *
10. The Definitive Guide to Pylons
11. Making Games with Python & Pygame
12. Python Module of the Week
14. Think Complexity
15. Data Structures and Algorithms with Object-Oriented Design Patterns in Python
16. Programming Computer Vision with Python
17. Python for you and me 0.2
18. Problem Solving with Algorithms and Data Structures using Python
19. The Art and Craft of Programming Python Edition
20. Python Programming
Python编程实践
Python学习手册 第x版
Python标准库
Python Cook Book(http://wiki.woodpecker.org.cn/moin/PyCookbook#head-46f748fbcc7334428c9de66085983ae69a4e8494)
如何入门
http://blog.csdn.net/wklken/article/details/7907560
http://timgolden.me.uk/python/
Copy and DeepCopy
importcopy
al= [[1],[2],[3]]
bl=copy.copy(al)
cl=copy.deepcopy(al)print "before=>"
print al #[[1], [2], [3]]
print bl #[[1], [2], [3]]
print cl #[[1], [2], [3]]
al[0][0]=0
al[1] =Noneprint "after=>"
print al #[[0], None, [3]]
print bl #[[0], [2], [3]]
print cl #[[1], [2], [3]]
#---------------------------------------------
importcopy
al= [1,2,3]
bl=copy.copy(al)
cl=copy.deepcopy(al)print "before=>"
print al #[[1], [2], [3]]
print bl #[[1], [2], [3]]
print cl #[[1], [2], [3]]
al[0]=0
al[1] =Noneprint "after=>"
print al #[0, None, 3]
print bl #[1, 2, 3]
print cl #[1, 2, 3]
Send Email
importsmtplibfrom email.mime.text importMIMEText
mailto_list= ['yaoyansi@aliyun.com']
mail_user= "yaoyansi"mail_postfix= "aliyun.com"
defsend_mail(to_list,sub,content):
me="hello"+""msg= MIMEText(content,_subtype='plain',_charset='gb2312')
msg['Subject'] =sub
msg['From'] =me
msg['To'] = ";".join(to_list)try:
server= smtplib.SMTP('localhost')
server.sendmail(me, to_list, msg.as_string())
server.close()returnTrueexceptException, e:printstr(e)returnFalseif __name__ == '__main__':if send_mail(mailto_list,"hello","hello world!"):print "good"
else:print "bad"
View Code
- function trace
def flog(format, *params):print("mytest:"+format %params)defmyfunction(a, b)
flog("%s %s", sys._getframe().f_code.co_name, locals())pass
- replace '\' with '/':
full_path = os.path.realpath(__file__);
full_path = full_path.replace('\\','/')
http://www.pythonscripting.com
A Brief Introduction to Python with Only One Figure
20 of the Best Free Python Books
1. Think Python
2. Invent Your Own Computer Games with Python
3. Snake Wrangling for Kids
4. Learn Python the Hard Way, 2nd Edition
5. Natural Language Processing with Python
6. Building Skills in Python
7. Dive into Python
8. Text Processing in Python
9. The Standard Python Library *
10. The Definitive Guide to Pylons
11. Making Games with Python & Pygame
12. Python Module of the Week
14. Think Complexity
15. Data Structures and Algorithms with Object-Oriented Design Patterns in Python
16. Programming Computer Vision with Python
17. Python for you and me 0.2
18. Problem Solving with Algorithms and Data Structures using Python
19. The Art and Craft of Programming Python Edition
20. Python Programming
Python编程实践
Python学习手册 第x版
Python标准库
Python Cook Book(http://wiki.woodpecker.org.cn/moin/PyCookbook#head-46f748fbcc7334428c9de66085983ae69a4e8494)
如何入门
http://blog.csdn.net/wklken/article/details/7907560
http://timgolden.me.uk/python/
Copy and DeepCopy
importcopy
al= [[1],[2],[3]]
bl=copy.copy(al)
cl=copy.deepcopy(al)print "before=>"
print al #[[1], [2], [3]]
print bl #[[1], [2], [3]]
print cl #[[1], [2], [3]]
al[0][0]=0
al[1] =Noneprint "after=>"
print al #[[0], None, [3]]
print bl #[[0], [2], [3]]
print cl #[[1], [2], [3]]
#---------------------------------------------
importcopy
al= [1,2,3]
bl=copy.copy(al)
cl=copy.deepcopy(al)print "before=>"
print al #[[1], [2], [3]]
print bl #[[1], [2], [3]]
print cl #[[1], [2], [3]]
al[0]=0
al[1] =Noneprint "after=>"
print al #[0, None, 3]
print bl #[1, 2, 3]
print cl #[1, 2, 3]
Send Email
View Code
importre
str= r'
'p= re.compile(r'<.>')print p.match(str).group(0) #print p.match(str).span() #(0, 6)