python简单介绍
TRANSCRIPT
特点
2
简单易学
3
功能强大
4
兼容性好
5
扩展性好
6
开源
7
例子
8
好工具iPython
9
内建函数build-in
10
11
open,range,lambda
12
map,filter
13
模块
14
sys,os
15
time,datetime
16
hashlib
17
Tips
18
[i for i in lst if i]
19
[i.strip() for i in lst if i]
20
def fun(arg1,arg2)
d={arg1:11,arg2:22}
fun(d[arg1],d[arg2])
fun(**d)
21
p = [a,b,c]#want a/b/cos.path.join(*p)
22
a=[a,b,c]#want a_b_c or a*b*c’_’.join(a)’*’.join(a)b=’fuck’#want fuck! fuck!...”%s! ” % (b) * 20
23
源代码style guide
24
tab,space
25
def fun():tab>a=xx....return a
26
好4个space
27
#!/usr/bin/env python# coding=utf-8
# -*- coding: utf-8 -*-
28
#NOimport os,sys#Yesimport osimport sys#Butfrom os import popen,popen2
29
#Yesa = 1 + 2blockq = 3 + 4#Noa = 1 + 2blockq = 3 + 4
30
1行不超79etc.
31
Py3khas come
32
Style Changes
33
4-spaceONLY
34
• None, as 成了关键字
• print 成了函数
• dict.has_key 改用in操作符
• int和long没有差别了
• 所有的strings都是Unicode
• 不可比的类型之间比较将出异常
• <>操作符没有了,!=代替
• apply()用f(*args,**kw)代替
• xrange()用rang()代替
• map和filter没有了,list可以管
• etc.
35
ModuleChanges
36
• Removed
• sha,md5: hashlib代替
• mimetools: email package代替
• timing: time.clock()代替
• Renamed
• cPickle: _pickle
• StringIO/cStringIO: 成了io的一个class
• HTMLParser: http.client
• BaseHTTPServer: http.server
• CGIHTTPServer: http.server
• SimpleHTTPServer: http.server
37
路漫漫其修远兮!
38
Q&A?
39
参考资料• PEP: http://www.python.org/dev/peps/
• 8: Style Guide for Python Code
• 3000: Python 3000
• 263: Defining Python Source Code Encodings
• Py3k: http://wiki.python.org/moin/Python3.0
• Python Shell Tab Completion: http://blog.yzlin.org/2008/12/22/75/
40
• iPython: http://ipython.scipy.org/moin/
• python常用模块: http://wiki.woodpecker.org.cn/moin/PyCommonUsageMod
• python中文处理: http://wiki.woodpecker.org.cn/moin/PyInChinese
• Python编辑速度技巧: http://wiki.woodpecker.org.cn/moin/PyOptimize
• vim的tabstop: http://blog.khsing.net/2008/12/vims-tabstop.html
41
Thanks!
42