- unimport a module
import sys import AA.BB as CC; del sys.modules["AA.BB"]
- function trace
def flog(format, *params): print("mytest: "+format % params) def myfunction(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
unit test: https://docs.python.org/2/library/unittest.html
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
import copy 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] = None print "after=>" print al #[[0], None, [3]] print bl #[[0], [2], [3]] print cl #[[1], [2], [3]] #--------------------------------------------- import copy 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] = None print "after=>" print al #[0, None, 3] print bl #[1, 2, 3] print cl #[1, 2, 3]
Send Email
import smtplib from email.mime.text import MIMEText mailto_list = ['yaoyansi@aliyun.com'] mail_user = "yaoyansi" mail_postfix = "aliyun.com" def send_mail(to_list,sub,content): me ="hello"+"<"+mail_user+"@"+mail_postfix+">" 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() return True except Exception, e: print str(e) return False if __name__ == '__main__': if send_mail(mailto_list,"hello","hello world!"): print "good" else: print "bad"
- function trace
def flog(format, *params): print("mytest: "+format % params) def myfunction(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
unit test: https://docs.python.org/2/library/unittest.html
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
import copy 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] = None print "after=>" print al #[[0], None, [3]] print bl #[[0], [2], [3]] print cl #[[1], [2], [3]] #--------------------------------------------- import copy 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] = None print "after=>" print al #[0, None, 3] print bl #[1, 2, 3] print cl #[1, 2, 3]
Send Email
import re str = r'<html><title></title></html>' p = re.compile(r'<.*?>') print p.match(str).group(0) #<html> print p.match(str).span() #(0, 6)