python简单介绍

42
Python 简单介绍 Guixing Bai [email protected] 1

Upload: guixing-bai

Post on 17-Jul-2015

934 views

Category:

Technology


5 download

TRANSCRIPT

Page 2: Python简单介绍

特点

2

Page 3: Python简单介绍

简单易学

3

Page 4: Python简单介绍

功能强大

4

Page 5: Python简单介绍

兼容性好

5

Page 6: Python简单介绍

扩展性好

6

Page 7: Python简单介绍

开源

7

Page 8: Python简单介绍

例子

8

Page 9: Python简单介绍

好工具iPython

9

Page 10: Python简单介绍

内建函数build-in

10

Page 11: Python简单介绍

print

11

Page 12: Python简单介绍

open,range,lambda

12

Page 13: Python简单介绍

map,filter

13

Page 14: Python简单介绍

模块

14

Page 15: Python简单介绍

sys,os

15

Page 16: Python简单介绍

time,datetime

16

Page 17: Python简单介绍

hashlib

17

Page 18: Python简单介绍

Tips

18

Page 19: Python简单介绍

[i for i in lst if i]

19

Page 20: Python简单介绍

[i.strip() for i in lst if i]

20

Page 21: Python简单介绍

def fun(arg1,arg2)

d={arg1:11,arg2:22}

fun(d[arg1],d[arg2])

fun(**d)

21

Page 22: Python简单介绍

p = [a,b,c]#want a/b/cos.path.join(*p)

22

Page 23: Python简单介绍

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

Page 24: Python简单介绍

源代码style guide

24

Page 25: Python简单介绍

tab,space

25

Page 26: Python简单介绍

def fun():tab>a=xx....return a

26

Page 27: Python简单介绍

好4个space

27

Page 28: Python简单介绍

#!/usr/bin/env python# coding=utf-8

# -*- coding: utf-8 -*-

28

Page 29: Python简单介绍

#NOimport os,sys#Yesimport osimport sys#Butfrom os import popen,popen2

29

Page 30: Python简单介绍

#Yesa = 1 + 2blockq = 3 + 4#Noa = 1 + 2blockq = 3 + 4

30

Page 31: Python简单介绍

1行不超79etc.

31

Page 32: Python简单介绍

Py3khas come

32

Page 33: Python简单介绍

Style Changes

33

Page 34: Python简单介绍

4-spaceONLY

34

Page 35: Python简单介绍

• None, as 成了关键字

• print 成了函数

• dict.has_key 改用in操作符

• int和long没有差别了

• 所有的strings都是Unicode

• 不可比的类型之间比较将出异常

• <>操作符没有了,!=代替

• apply()用f(*args,**kw)代替

• xrange()用rang()代替

• map和filter没有了,list可以管

• etc.

35

Page 36: Python简单介绍

ModuleChanges

36

Page 37: Python简单介绍

• 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

Page 38: Python简单介绍

路漫漫其修远兮!

38

Page 39: Python简单介绍

Q&A?

39

Page 40: Python简单介绍

参考资料• 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

Page 42: Python简单介绍

Thanks!

42