python2.7
python3.5
一个据说是在圣诞节期间无聊写的。。。。
万恶的资本主义假期真长!!!
好不容易放个假多睡会觉不行吗!!!
1,确认安装
安了python2.7.6跟python3.4.0
- senrsl@senrsl-T540p:~/test$ python
- Python 2.7.6 (default, Jun 22 2015, 17:58:13)
- [GCC 4.8.2] on linux2
- Type "help", "copyright", "credits" or "license" for more information.
- >>> exit
- Use exit() or Ctrl-D (i.e. EOF) to exit
- >>> exit()
- senrsl@senrsl-T540p:~/test$ python3
- Python 3.4.0 (default, Jun 19 2015, 14:20:21)
- [GCC 4.8.2] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> exit()
- senrsl@senrsl-T540p:~/test$ mkdir python3
- senrsl@senrsl-T540p:~/test$ cd python3/
- senrsl@senrsl-T540p:~/test/python3$ ll
- 总用量 8
- drwxrwxr-x 2 senrsl senrsl 4096 6月 14 11:12 ./
- drwxrwxr-x 10 senrsl senrsl 4096 6月 14 11:12 ../
- senrsl@senrsl-T540p:~/test/python3$
2,Hello,World
1)命令行输出
- senrsl@senrsl-T540p:~/test/python3$ python3
- Python 3.4.0 (default, Jun 19 2015, 14:20:21)
- [GCC 4.8.2] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> 100+200
- 300
- >>> 1+2
- 3
- >>> 2*3
- 6
- >>> 2/3
- 0.6666666666666666
- >>> 2/0
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- ZeroDivisionError: division by zero
- >>> print("hello,world");
- hello,world
- >>> exit
- Use exit() or Ctrl-D (i.e. EOF) to exit
- >>> exit();
- senrsl@senrsl-T540p:~/test/python3$
2)文件输出
目测appstore_tanzhen走错片场。。。。
- senrsl@senrsl-T540p:~/test/python3$ touch helloWorld.py
- senrsl@senrsl-T540p:~/test/python3$ echo print('hello,world!')>>helloWorld.py
- bash: 未预期的符号 `(' 附近有语法错误
- senrsl@senrsl-T540p:~/test/python3$ echo "print('hello,world!')">>helloWorld.py
- echo "print('hello,world'/home/senrsl/下载 /Appstore_1.0.1012.1_Cadillac_X(20160530)_tanzhen.apk' )">>helloWorld.py
- senrsl@senrsl-T540p:~/test/python3$ cat helloWorld.py
- print('hello,world'/home/senrsl/下载 /Appstore_1.0.1012.1_Cadillac_X(20160530)_tanzhen.apk' )
- senrsl@senrsl-T540p:~/test/python3$ echo "print('hello,world!')">>helloWorld.py
- echo "print('hello,world'/home/senrsl/下载 /Appstore_1.0.1012.1_Cadillac_X(20160530)_tanzhen.apk' )">>helloWorld.py
- senrsl@senrsl-T540p:~/test/python3$ echo "print('hello,world')">>helloWorld.pysenrsl@senrsl-T540p:~/test/python3$ cat helloWorld.py
- print('hello,world'/home/senrsl/下载 /Appstore_1.0.1012.1_Cadillac_X(20160530)_tanzhen.apk' )
- print('hello,world'/home/senrsl/下载 /Appstore_1.0.1012.1_Cadillac_X(20160530)_tanzhen.apk' )
- print('hello,world')
- senrsl@senrsl-T540p:~/test/python3$ echo "print('hello,world')">helloWorld.py
- senrsl@senrsl-T540p:~/test/python3$ cat helloWorld.py
- print('hello,world')
- senrsl@senrsl-T540p:~/test/python3$ python3 helloWorld.py
- hello,world
- senrsl@senrsl-T540p:~/test/python3$
3)可执行文件
跟linux shell一样,告诉系统去找什么,然后chmod加权限
- senrsl@senrsl-T540p:~/test/python3$ gedit helloWorld.py
- senrsl@senrsl-T540p:~/test/python3$ cat helloWorld.py
- #!/usr/bin/env python3
- print('hello,world')
- senrsl@senrsl-T540p:~/test/python3$ chmod a+x helloWorld.py
- senrsl@senrsl-T540p:~/test/python3$ ./helloWorld.py
- hello,world
- senrsl@senrsl-T540p:~/test/python3$
4)输入输出
定义变量name接收函数input()的接收内容,可以直接输入变量名查看结果,或使用print()函数打印
- senrsl@senrsl-T540p:~/test/python3$ python3
- Python 3.4.0 (default, Jun 19 2015, 14:20:21)
- [GCC 4.8.2] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> name = input();
- senRsl
- >>> name
- 'senRsl'
- >>> print(name);
- senRsl
- >>> name = input("名字:");
- 名字:senRsl
- >>> print("你好,",name);
- 你好, senRsl
- >>> print("1024 * 768 = ",1024*768);
- 1024 * 768 = 786432
- >>>
3,基本语法
1)规范
①#号后是注释;
②:号后是代码块;
③缩进标准为4个空格;
④大小写敏感;
⑤弱数据类型
2)数据类型与运算符
①整数:无大小限制
②浮点:超出范围会报inf(infinty)
③字符串:堆,引用
④布尔:True/False
⑤逻辑运算符:and,or,not(单目,同非~)
⑥算数运算符:+,-,*,**(幂),/(除以),//(地板除/floor division/向下取整/商),%(取余);
⑦空:None
⑧集合:
a)list(列表,有序,一个又像数组又像集合的东西),
b)tuple(元组[ tʌpl ],有序,元素指向不可变),
c)dict(字典,dictionary,键值对key-value,key不能重复,无序),
d)set(无序,不可重复,创建于list);
⑨应该有其他吧
基本数据类型:
字符r表示字符串默认不转义:
- >>> print("fuck\n \t \" ' \\ ok");
- fuck
- " ' \ ok
- >>> 1>1
- False
- >>> 1>1 or True
- True
- >>> 1>1 and True
- False
- >>> 1>1 not True
- File "<stdin>", line 1
- 1>1 not True
- ^
- SyntaxError: invalid syntax
- >>> not True
- False
- >>> not 1
- False
- >>>
列表list的用法:
- >>> n=123;f=456.789;
- >>> s1="Hello,world!";s2="Hello,\'Adam\'";s3=r"Hello,'Bart'";s4=r'''Hello,
- ... Lisa!''';
- >>> print(n,f,s1,s2,s3,s4);
- 123 456.789 Hello,world! Hello,'Adam' Hello,'Bart' Hello,
- Lisa!
- >>>
列表tuple的用法:
- senrsl@senrsl-T540p:~$ python3
- Python 3.4.0 (default, Jun 19 2015, 14:20:21)
- [GCC 4.8.2] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> names = ["小A","小B","大C"];
- >>> names
- ['小A', '小B', '大C']
- >>> len(names);
- 3
- >>> names[0];
- '小A'
- >>> names[2]
- '大C'
- >>> names[-1];
- '大C'
- >>> names[-2];
- '小B'
- >>> names.append("D");
- >>> names
- ['小A', '小B', '大C', 'D']
- >>> names.insert(3,'小C');
- >>> names
- ['小A', '小B', '大C', '小C', 'D']
- >>> names.pop();
- 'D'
- >>> names
- ['小A', '小B', '大C', '小C']
- >>> names.pop(1);
- '小B'
- >>> names
- ['小A', '大C', '小C']
- >>> names[1]= "小B";
- >>> names
- ['小A', '小B', '小C']
- >>> names.append(123);
- >>> names.append(True);
- >>> names
- ['小A', '小B', '小C', 123, True]
- >>> name2s = ["2小A","2小B","2大C"];
- >>> name2s
- ['2小A', '2小B', '2大C']
- >>> names.append(name2s);
- >>> names
- ['小A', '小B', '小C', 123, True, ['2小A', '2小B', '2大C']]
- >>> names[5][2]
- '2大C'
- >>>
列表里的内容是可以重复的:
- >>> tuple = (1,2);
- >>> tuple
- (1, 2)
- >>> tuple1 = (1,);
- >>> tuple1
- (1,)
- >>>
字典dict的用法:
- >>> L = [ ["A","G","M"],["J","P","R","P"],["A","B","L"] ];
- >>> L
- [['A', 'G', 'M'], ['J', 'P', 'R', 'P'], ['A', 'B', 'L']]
- >>> print(L[0][0]);
- A
- >>> print(L[1][1]);
- P
- >>> print(L[2][2]);
- L
- >>>
set的用法:
- >>> names = {"小A":1,"小B":2,"大C":3};
- >>> names["小B"]
- 2
- >>> names["D"]=4
- >>> names
- {'小B': 2, 'D': 4, '大C': 3, '小A': 1}
- >>> "小B" in names
- True
- >>> names.get("小B");
- 2
- >>> names.pop("小B");
- 2
- >>> names
- {'D': 4, '大C': 3, '小A': 1}
- >>>
- >>> s = set([1,2,3]);
- >>> s
- {1, 2, 3}
- >>> s = set([1,2,3,0,1,2,3]);
- >>> s
- {0, 1, 2, 3}
- >>> s.add(-1);
- >>> s
- {0, 1, 2, 3, -1}
- >>> s.remove(-1);
- >>> s
- {0, 1, 2, 3}
- >>> s1 = set([1,2]);
- >>> s & s1
- {1, 2}
- >>> s | s1
- {0, 1, 2, 3}
- >>>
3)编码
①字符编解码
②源代码编码
- >>> ord("A");
- 65
- >>> chr(65);
- 'A'
- >>> "A".encode("ascii");
- b'A'
- >>> "A".encode("utf-8");
- b'A'
- >>> "A".encode("gb2312");
- b'A'
- >>> "啊".encode("utf-8");
- b'\xe5\x95\x8a'
- >>> b'\xe5\x95\x8a'.decode("utf-8");
- '啊'
- >>> len("啊");
- 1
- >>>
在源代码中声明文件编码,是为了让python知道用什么编码读
4)格式化输出
- senrsl@senrsl-T540p:~/test/python3$ cat helloWorld.py
- #!/usr/bin/env python3
- print('hello,world');
- print("你好,大爷");
- senrsl@senrsl-T540p:~/test/python3$ python helloWorld.py
- File "helloWorld.py", line 5
- SyntaxError: Non-ASCII character '\xe4' in file helloWorld.py on line 5, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
- senrsl@senrsl-T540p:~/test/python3$ gedit helloWorld.py
- senrsl@senrsl-T540p:~/test/python3$ cat helloWorld.py
- #!/usr/bin/env python3
- # -*- coding: utf-8 -*-
- print('hello,world');
- print("你好,大爷");
- senrsl@senrsl-T540p:~/test/python3$ python3 helloWorld.py
- hello,world
- 你好,大爷
- senrsl@senrsl-T540p:~/test/python3$
格式化输出:
说明
- >>> print("hello,%s!do you know %d + %00d = %.2f,%% is \%" %(input("name:"),int(input("整数:")),int(input("整数2号:")),float(input("浮点 数:")) ));
- name:world
- 整数:1
- 整数2号:2
- 浮点数:3
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- ValueError: incomplete format
- >>> print("hello,%s!do you know %d + %00d = %.2f,%% is %%" %(input("name:"),int(input("整数:")),int(input("整数2号:")),float(input("浮点 数:")) ));
- name:worldddddd
- 整数:1
- 整数2号:2
- 浮点数:3
- hello,worldddddd!do you know 1 + 2 = 3.00,% is %
- >>> print("hello,%s!do you know %d + %00d = %.2f,%% is %%" %(input("name:"),int(input("整数:")),int(input("整数2号:")),float(input("浮点 数:")) ));
- name:worldd
- 整数:1
- 整数2号:2
- 浮点数:3.1234567
- hello,worldd!do you know 1 + 2 = 3.12,% is %
- >>>
①input()函数接收到的都是字符串;
②%的转义必须是%%,不能是\%;
小明再现
- >>> print("%.1f"% ((85-72)/85) );
- 0.2
- >>>
5)控制语句
①条件语句if-else
注意冒号跟四个空格
- >>> if 1>2:
- ... print("1大于20");
- ... else:
- ... print("2大于1");
- ...
- 2大于1
- >>>
②循环语句for-in
心算
- >>> for l in L:
- ... print(l);
- ...
- ['A', 'G', 'M']
- ['J', 'P', 'R', 'P']
- ['A', 'B', 'L']
- >>>
- >>> for x in range(101):
- ... sum = sum + x;
- ...
- >>> print(sum);
- 5050
- >>>
③循环语句while
小心死循环
- senrsl@senrsl-T540p:~$ python3
- Python 3.4.0 (default, Jun 19 2015, 14:20:21)
- [GCC 4.8.2] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> sum = 0;i=0;
- >>> while i<100:
- ... sum = sum+i;
- ... i = i + 1;
- ...
- >>> print(sum);
- 4950
- >>>
4,函数
1)API
地址:https://docs.python.org/
或者内置的使用help(xxx);q退出
2)数据类型转换函数
最后一个是函数的别名。
- >>> int("1");
- 1
- >>> int("1.1");
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- ValueError: invalid literal for int() with base 10: '1.1'
- >>> int(1.1);
- 1
- >>> float("1.1");
- 1.1
- >>> float(1);
- 1.0
- >>> str(111);
- '111'
- >>> bool(1);
- True
- >>> bool(0);
- False
- >>> bool("111");
- True
- >>> bool("");
- False
- >>> i = int;
- >>> i("111");
- 111
- >>>
3)定义函数
拿来占位置的pass:
- >>> def testMethod(x):
- ... print(x);
- ...
- >>> testMethod("sssss");
- sssss
- >>> t = testMethod;
- >>> t("测试");
- 测试
- >>> print(t("测"));
- 测
- None
- >>>
参数检查:
- >>> def nop():
- ... pass;
- ...
- >>> nop();
- >>>
函数返回多个值:
- >>> def testMethod01(x):
- ... if not isinstance(x,(int,float)):
- ... raise TypeError("类型错误");
- ... print("输出",x);
- ...
- >>> t1 = testMethod01;
- >>> t1("123");
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "<stdin>", line 3, in testMethod01
- TypeError: 类型错误
- >>> t1(123);
- 输出 123
- >>>
返回的就是一个tuple
- >>> import math;
- >>> def testMath(x,y,z=0):
- ... return x+y,x-y,z;
- ...
- >>> t2 = testMath;
- >>> t2(1,2);
- (3, -1, 0)
- >>> x,y = t2(1,2);
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- ValueError: too many values to unpack (expected 2)
- >>> x = t2(1,2);
- >>> print(x);
- (3, -1, 0)
- >>>
一元二次方程是什么。。。。
4)参数
好乱的参数
尾递归,就是每运算一次就得出相应结果,然后进行下次运算。
- >>> def testMethod02(x,y=1,z=2,a="fuck",*args,**kw):
- ... print(x,y,z,a,args,kw);
- ...
- >>> testMethod02(1);
- 1 1 2 fuck () {}
- >>> def testMethod03(x,y,z=0,*,a,**kw):
- ... print(x,y,z,a,kw);
- ...
- >>> testMethod03(1,2,a=111,ext=None);
- 1 2 0 111 {'ext': None}
- >>> args = (1,2,3,4);
- >>> kw = {"d":111,"dd":111111};
- >>> testMethod02(*args,**kw);
- 1 2 3 4 () {'d': 111, 'dd': 111111}
- >>> args = (1,2,3,4,5);
- >>> testMethod02(*args,**kw);
- 1 2 3 4 (5,) {'d': 111, 'dd': 111111}
- >>>
5,高级特性
1)切片Slice
切list:
切tuple:
- >>> L = ["A0","B1","C2","D3","E4"];
- >>> L[0:3];
- ['A0', 'B1', 'C2']
- >>> L[:3];
- ['A0', 'B1', 'C2']
- >>> L[-2:]
- ['D3', 'E4']
- >>> L[:];
- ['A0', 'B1', 'C2', 'D3', 'E4']
- >>>
切字符串:
- >>> (0,1,2,3,4,5)[:3]
- (0, 1, 2)
- >>>
隔空取物:
- >>> "ABCDE"[:3]
- 'ABC'
上面是10-15,每隔5个取一个;
- >>> L = list(range(100));
- >>> L[10:50:5];
- [10, 15, 20, 25, 30, 35, 40, 45]
- >>> L[::10];
- [0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
- >>>
所有数,隔10个取一个;
2)迭代Iteration
迭代map:
带下标的迭代:
- >>> dict = {"A":0,"B":1,"C":2,"D":3};
- >>> for key in dict:
- ... print(key);
- ...
- C
- A
- B
- D
- >>> for value in dict:
- ... print(value);
- ...
- C
- A
- B
- D
- >>> for value in dict.values():
- ... print(value);
- ...
- 2
- 0
- 1
- 3
- >>> for k,v in dict.items():
- ... print(k,v);
- ...
- C 2
- A 0
- B 1
- D 3
- >>>
判断是不是可以被迭代:
- >>> for i,v in enumerate(["A","B","C"]):
- ... print(i,v);
- ...
- 0 A
- 1 B
- 2 C
- >>>
- >>> for i,v in enumerate("ABCDEFG"):
- ... print(i,v);
- ...
- 0 A
- 1 B
- 2 C
- 3 D
- 4 E
- 5 F
- 6 G
- >>>
- >>> from collections import Iterable;
- >>> isinstance("abcdeeeee",Iterable);
- True
- >>> isinstance([0,1,2,3],Iterable);
- True
- >>> isinstance(12344,Iterable);
- False
- >>>
3)列表生成器List Comprehensions
懒得吐槽
- >>> [x * x for x in range(1,11)];
- [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
- >>> [x * x for x in range(1,11)if x % 2 ==0 ];
- [4, 16, 36, 64, 100]
- >>>
- >>> [ m +n for m in "ABC" for n in "XYZ"];
- ['AX', 'AY', 'AZ', 'BX', 'BY', 'BZ', 'CX', 'CY', 'CZ']
- >>>
- >>> import os;
- >>> [d for d in os.listdir(".")];
- ['.charles', '.subversion', '.rnd', '.hardinfo', '.android', '.bashrc~', '.gradle', '.charles.config', '.AndroidStudio1.4', '.gerritcodereview', '.hplip', 'examples.desktop', '.profile', '.bash_history', '.ssh', '.audacity-data', '.ICEauthority', '公共的', '.repo_.gitconfig.json', '模板', '桌面', '.p2', 'share', 'doc', '图片', '音乐', '.dbus', '.config', '.thumbnails', '.gnome', '.bashrc.save.1', '.repopickle_.gitconfig', '.python_history', '.kingsoft', '文档', 'java', '.gphoto', '.gnome2_private', '.gnome2', '.wine', 'test', '视频', '.bashrc.save', '.mozilla', 'android', '.nvidia-settings-rc', '.bashrc', '.remmina', '.m2', '.thunderbird', '.bash_logout', '.jack', '.compiz', '.local', '.eclipse', '.cache', '.Xauthority', '.sunpinyin', '.repoconfig', '.apport-ignore.xml', '.java', 'j2ee', 'PRETTY_HOSTNAME=SENRSL_UBT', '.xsession-errors.old', '.lesshst', '.dmrc', '.xinputrc', '.gitconfig', '.git-credentials', 'VirtualBox VMs', '.gksu.lock', '.gconf', '.pki', 'tools', '.gitconfig~', '下载', '.freerdp', '.gvfs', '.idm', '.xsession-errors', '.npm', '.nv', '.gimp-2.8']
- >>>
4)生成器generator
第一种:
- >>> g = (x * x for x in range(10));
- >>> for n in g:
- ... print(n);
- ...
- 0
- 1
- 4
- 9
- 16
- 25
- 36
- 49
- 64
- 81
- >>> g
- <generator object <genexpr> at 0x7fd2484e78b8>
- >>>
第二种:
W)读取的时候会记住上次读取的位置,读到最后再接着读就不到了
- >>> def fibonacci(max):
- ... n,a,b = 0,0,1;
- ... while n < max:
- ... yield b;
- ... a,b = b,a+b;
- ... n = n+1;
- ... return "done";
- ...
- >>> f1 = fibonacci(6);
- >>> f1
- <generator object fibonacci at 0x7fd2484da558>
- >>>
- >>> f1 = fibonacci(6);
- >>> while(1):
- ... try:
- ... x = next(f1);
- ... print(x);
- ... except StopIteration as e:
- ... print(e.value);
- ... break;
- ...
- 1
- 1
- 2
- 3
- 5
- 8
- done
- >>> while(1):
- ... try:
- ... x = next(f1);
- ... print(x);
- ... except StopIteration as e:
- ... print(e.value);
- ... break;
- ...
- None
- >>>
杨辉三角:
法1)
- >>> def pas_triangles():
- ... a = [1];
- ... while True:
- ... yield a;
- ... a = [ sum(i) for i in zip([0] + a,a+[0]) ];
- ...
- >>> g = pas_triangles();
- >>> for n in range(10):
- ... print(next(g));
- ...
- [1]
- [1, 1]
- [1, 2, 1]
- [1, 3, 3, 1]
- [1, 4, 6, 4, 1]
- [1, 5, 10, 10, 5, 1]
- [1, 6, 15, 20, 15, 6, 1]
- [1, 7, 21, 35, 35, 21, 7, 1]
- [1, 8, 28, 56, 70, 56, 28, 8, 1]
- [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]
- >>>
法2):
以上,俩函数完全看不懂。。。。
- >>> def pas_triangles():
- ... N = [1];
- ... while True:
- ... yield N;
- ... N.append(0);
- ... N = [ N[i-1] + N[i] for i in range(len(N)) ];
- ...
- >>> g2 = pas_triangles();
- >>> for n in range(10):
- ... print(next(g2));
- ...
- [1]
- [1, 1]
- [1, 2, 1]
- [1, 3, 3, 1]
- [1, 4, 6, 4, 1]
- [1, 5, 10, 10, 5, 1]
- [1, 6, 15, 20, 15, 6, 1]
- [1, 7, 21, 35, 35, 21, 7, 1]
- [1, 8, 28, 56, 70, 56, 28, 8, 1]
- [1, 9, 36, 84, 126, 126, 84, 36, 9, 1]
- >>>
6,函数式编程Functional Programming
1)高阶函数Higher-order function
函数名也是变量;
变量可以指向函数;
函数参数可以传入函数;
示例如下:
把函数作为参数传入,就是高阶函数。函数式编程就是这种高度抽象的编程范式。
- >>> def a(a,b,f):
- ... return f(a) + f(b);
- ...
- >>> a(5,6,abs);
- 11
- >>>
①map:
map的作用是把函数依次作用到每个元素。
②reduce:
- >>> def f3(x):
- ... return x * x;
- ...
- >>> r = map(f3,[1,2,3,4,5,6,7,8,9]);
- >>> list(r);
- [1, 4, 9, 16, 25, 36, 49, 64, 81]
- >>>
reduce的作用是把函数作用在一个序列上。
③filter:
- >>> from functools import reduce;
- >>> def add(x,y):
- ... return x+y;
- ...
- >>> reduce(add,[1,2,3,4,5,6,7,8,9]);
- 45
- >>>
filter的作用是对每个元素进行过滤。
④sorted:
- >>> def notEmpty(s):
- ... return s and s.strip();
- ...
- >>> list(filter(notEmpty,["A","B",None,"C",""," "," "]));
- ['A', 'B', 'C']
- >>>
sorted对每个元素进行排序。
>>> sorted([2,1,3,5,4,9,4,2,1,8]);
第四行的是绝对值后再排序;
- [1, 1, 2, 2, 3, 4, 4, 5, 8, 9]
- >>> sorted([2,1,3,5,4,-9,4,2,-1,8]);
- [-9, -1, 1, 2, 2, 3, 4, 4, 5, 8]
- >>> sorted([2,1,3,5,4,-9,4,2,-1,8],key=abs);
- [1, -1, 2, 2, 3, 4, 4, 5, 8, -9]
- >>> sorted([2,1,3,5,4,-9,4,2,-1,8],key=abs,reverse=True);
- [-9, 8, 5, 4, 4, 3, 2, 2, 1, -1]
- >>>
第六行的是排序结果反转。
2)闭包
函数里的函数
- >>> def count():
- ... fs = [];
- ... for i in range(1,4):
- ... def f():
- ... return i*i;
- ... fs.append(f);
- ... return fs;
- ...
- >>> f1,f2,f3 = count();
- >>> f1();
- 9
- >>> f1
- <function count.<locals>.f at 0x7fd2484dbb70>
- >>> f2();
- 9
- >>> f3();
- 9
- >>>
3)匿名函数
关键字lambda表示匿名函数;
冒号前面的x表示函数参数;
只能有一个表达式;
- >>> list(map(lambda x:x*x,[1,2,3,4,5,6,7,8,94]));
- [1, 4, 9, 16, 25, 36, 49, 64, 8836]
- >>>
4)装饰器decorator
在代码运行期间动态增加功能的方式。
二层嵌套:
- >>> f3.__name__
- 'f'
- >>> f1.__name__
- 'f'
- >>> def log(func):
- ... def wrapper(*args,**kw):
- ... print("call %s():" % func.__name__);
- ... return func(*args,**kw);
- ... return wrapper;
- ...
- >>> @log
- ... def now():
- ... print("2016年06月17日11:21:34");
- ...
- >>> now();
- call now():
- 2016年06月17日11:21:34
- >>>
三层嵌套:
- >>> def log(text):
- ... def decorator(func):
- ... def wrapper(*args,**kw):
- ... print("%s %s():" % (text,func.__name__));
- ... return func(*args,**kw);
- ... return wrapper;
- ... return decorator;
- ...
- >>> @log("执行");
- File "<stdin>", line 1
- @log("执行");
- ^
- SyntaxError: invalid syntax
- >>> @log("执行")
- ... def now():
- ... print("2016年06月17日17:26:02");
- ...
- >>> now();
- 执行 now():
- 2016年06月17日17:26:02
- >>>
内置工具:
也是内置工具:
- >>> import functools;
- >>> def log(func):
- ... @functools.wraps(func)
- ... def wrapper(*args,**kw):
- ... print("call %s():" % func.__name__);
- ... return func(*args,**kw);
- ... return wrapper;
- ...
- >>> @log
- ... def now():
- ... print("2016年06月17日17:30:46");
- ...
- >>> now();
- call now():
- 2016年06月17日17:30:46
- >>>
这翻译我已经忍你很久了。。。。
- >>> import functools;
- >>> def log(text):
- ... def decorator(func):
- ... @functools.wraps(func)
- ... def wrapper(*args,**kw):
- ... print("%s %s():" % (text,func.__name__));
- ... return func(*args,**kw);
- ... return wrapper;
- ... return decorator;
- ...
- >>> @log("再次执行")
- ... def now():
- ... print("2016年06月17日17:34:14");
- ...
- >>> now();
- 再次执行 now():
- 2016年06月17日17:34:14
- >>>
这玩意就是个注解!!!
这翻译真能误导人。
5)偏函数Partial function
- >>> import functools;
- >>> int2 = functools.partial(int,base=2);
- >>> int2("100000");
- 32
- >>> int2("1111111");
- 127
- >>>
7,模块
一个.py文件就是一个模块Module。
按目录来组织模块,称为包Package。
每个包下面都要有一个__init__.py。
1)基本规则
建模块:
导入模块:
- senrsl@senrsl-T540p:~/test/python3$ touch helloWorld01.py
- senrsl@senrsl-T540p:~/test/python3$ vi helloWorld01.py
- senrsl@senrsl-T540p:~/test/python3$ cat helloWorld01.py
- #!/usr/bin/env python3
- # -*- coding:utf-8 -*-
- "这是注释"
- __author__ = "senRsl";
- import sys;
- def test():
- args = sys.argv;
- if len(args)==1:
- print("你好啊");
- elif len(args) == 2:
- print("Hello,%s" % args[1]);
- else:
- print("参数:",len(args));
- if __name__ == "__main__":
- test();
- senrsl@senrsl-T540p:~/test/python3$ chmod a+x helloWorld01.py
- senrsl@senrsl-T540p:~/test/python3$ python3 helloWorld01.py
- 你好啊
- senrsl@senrsl-T540p:~/test/python3$ python3 helloWorld01.py 00000
- Hello,00000
- senrsl@senrsl-T540p:~/test/python3$ python3 helloWorld01.py 00000 11111 2222
- 参数: 4
- senrsl@senrsl-T540p:~/test/python3$
- Python 3.4.0 (default, Jun 19 2015, 14:20:21)
- [GCC 4.8.2] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> import helloWorld01;
- >>> helloWorld01.test();
- 你好啊
- >>>
正常的都是public;
__xxx___这种是有特殊意义的;
_xx跟__xxx这种一般用作私有;
2)第三方模块
使用pip工具安装第三方模块
第三方模块在这里找:https://pypi.python.org/
安装pip工具:
安装图片处理库
- senrsl@senrsl-T540p:~/test/python3$ pip ?
- 程序"pip"尚未安装。 您可以使用以下命令安装:
- sudo apt-get install python-pip
- senrsl@senrsl-T540p:~/test/python3$ pip3 ?
- 程序"pip3"尚未安装。 您可以使用以下命令安装:
- sudo apt-get install python3-pip
- senrsl@senrsl-T540p:~/test/python3$ pip3 ?
- 程序"pip3"尚未安装。 您可以使用以下命令安装:
- sudo apt-get install python3-pip
- senrsl@senrsl-T540p:~/test/python3$ sudo apt-get install python3-pip
- [sudo] password for senrsl:
- 正在读取软件包列表... 完成
- 正在分析软件包的依赖关系树
- 正在读取状态信息... 完成
- 将会安装下列额外的软件包:
- libpython3-dev libpython3.4 libpython3.4-dev libpython3.4-minimal
- libpython3.4-stdlib python-chardet-whl python-colorama-whl
- python-distlib-whl python-html5lib-whl python-pip-whl python-requests-whl
- python-setuptools-whl python-six-whl python-urllib3-whl python3-colorama
- python3-dev python3-distlib python3-html5lib python3-setuptools
- python3-urllib3 python3-wheel python3.4 python3.4-dev python3.4-minimal
- 建议安装的软件包:
- python3-genshi python3.4-venv python3.4-doc
- 下列【新】软件包将被安装:
- libpython3-dev libpython3.4-dev python-chardet-whl python-colorama-whl
- python-distlib-whl python-html5lib-whl python-pip-whl python-requests-whl
- python-setuptools-whl python-six-whl python-urllib3-whl python3-colorama
- python3-dev python3-distlib python3-html5lib python3-pip python3-setuptools
- python3-wheel python3.4-dev
- 下列软件包将被升级:
- libpython3.4 libpython3.4-minimal libpython3.4-stdlib python3-urllib3
- python3.4 python3.4-minimal
- 升级了 6 个软件包,新安装了 19 个软件包,要卸载 0 个软件包,有 345 个软件包未被升级。
- 需要下载 24.9 MB 的软件包。
- 解压缩后会消耗掉 34.4 MB 的额外空间。
- 您希望继续执行吗? [Y/n] Y
- 获取:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python3-urllib3 all 1.7.1-1ubuntu4 [39.6 kB]
- 获取:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libpython3.4 amd64 3.4.3-1ubuntu1~14.04.3 [1,308 kB]
- 获取:3 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python3.4 amd64 3.4.3-1ubuntu1~14.04.3 [177 kB]
- 获取:4 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libpython3.4-stdlib amd64 3.4.3-1ubuntu1~14.04.3 [1,986 kB]
- 获取:5 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python3.4-minimal amd64 3.4.3-1ubuntu1~14.04.3 [1,223 kB]
- 获取:6 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libpython3.4-minimal amd64 3.4.3-1ubuntu1~14.04.3 [461 kB]
- 获取:7 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libpython3.4-dev amd64 3.4.3-1ubuntu1~14.04.3 [17.8 MB]
- 获取:8 http://archive.ubuntu.com/ubuntu/ trusty/main libpython3-dev amd64 3.4.0-0ubuntu2 [7,002 B]
- 获取:9 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe python-chardet-whl all 2.2.1-2~ubuntu1 [170 kB]
- 获取:10 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe python-colorama-whl all 0.2.5-0.1ubuntu2 [18.2 kB]
- 获取:11 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe python-distlib-whl all 0.1.8-1ubuntu1 [140 kB]
- 获取:12 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python-html5lib-whl all 0.999-3~ubuntu1 [109 kB]
- 获取:13 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python-six-whl all 1.5.2-1ubuntu1 [10.5 kB]
- 获取:14 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python-urllib3-whl all 1.7.1-1ubuntu4 [64.0 kB]
- 获取:15 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python-requests-whl all 2.2.1-1ubuntu0.3 [227 kB]
- 获取:16 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python-setuptools-whl all 3.3-1ubuntu2 [244 kB]
- 获取:17 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe python-pip-whl all 1.5.4-1ubuntu3 [111 kB]
- 获取:18 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe python3-colorama all 0.2.5-0.1ubuntu2 [12.0 kB]
- 获取:19 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python3.4-dev amd64 3.4.3-1ubuntu1~14.04.3 [419 kB]
- 获取:20 http://archive.ubuntu.com/ubuntu/ trusty/main python3-dev amd64 3.4.0-0ubuntu2 [1,192 B]
- 获取:21 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe python3-distlib all 0.1.8-1ubuntu1 [113 kB]
- 获取:22 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe python3-html5lib all 0.999-3~ubuntu1 [79.7 kB]
- 获取:23 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python3-setuptools all 3.3-1ubuntu2 [144 kB]
- 获取:24 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe python3-pip all 1.5.4-1ubuntu3 [80.3 kB]
- 获取:25 http://archive.ubuntu.com/ubuntu/ trusty-updates/main python3-wheel all 0.24.0-1~ubuntu1 [44.8 kB]
- 下载 24.9 MB,耗时 5分 6秒 (81.5 kB/s)
- (正在读取数据库 ... 系统当前共安装有 218132 个文件和目录。)
- 正准备解包 .../python3-urllib3_1.7.1-1ubuntu4_all.deb ...
- 正在将 python3-urllib3 (1.7.1-1ubuntu4) 解包到 (1.7.1-1ubuntu3) 上 ...
- 正准备解包 .../libpython3.4_3.4.3-1ubuntu1~14.04.3_amd64.deb ...
- 正在将 libpython3.4:amd64 (3.4.3-1ubuntu1~14.04.3) 解包到 (3.4.0-2ubuntu1.1) 上 ...
- 正准备解包 .../python3.4_3.4.3-1ubuntu1~14.04.3_amd64.deb ...
- 正在将 python3.4 (3.4.3-1ubuntu1~14.04.3) 解包到 (3.4.0-2ubuntu1.1) 上 ...
- 正准备解包 .../libpython3.4-stdlib_3.4.3-1ubuntu1~14.04.3_amd64.deb ...
- 正在将 libpython3.4-stdlib:amd64 (3.4.3-1ubuntu1~14.04.3) 解包到 (3.4.0-2ubuntu1.1) 上 ...
- 正准备解包 .../python3.4-minimal_3.4.3-1ubuntu1~14.04.3_amd64.deb ...
- 正在将 python3.4-minimal (3.4.3-1ubuntu1~14.04.3) 解包到 (3.4.0-2ubuntu1.1) 上 ...
- 正准备解包 .../libpython3.4-minimal_3.4.3-1ubuntu1~14.04.3_amd64.deb ...
- 正在将 libpython3.4-minimal:amd64 (3.4.3-1ubuntu1~14.04.3) 解包到 (3.4.0-2ubuntu1.1) 上 ...
- 正在选中未选择的软件包 libpython3.4-dev:amd64。
- 正准备解包 .../libpython3.4-dev_3.4.3-1ubuntu1~14.04.3_amd64.deb ...
- 正在解包 libpython3.4-dev:amd64 (3.4.3-1ubuntu1~14.04.3) ...
- 正在选中未选择的软件包 libpython3-dev:amd64。
- 正准备解包 .../libpython3-dev_3.4.0-0ubuntu2_amd64.deb ...
- 正在解包 libpython3-dev:amd64 (3.4.0-0ubuntu2) ...
- 正在选中未选择的软件包 python-chardet-whl。
- 正准备解包 .../python-chardet-whl_2.2.1-2~ubuntu1_all.deb ...
- 正在解包 python-chardet-whl (2.2.1-2~ubuntu1) ...
- 正在选中未选择的软件包 python-colorama-whl。
- 正准备解包 .../python-colorama-whl_0.2.5-0.1ubuntu2_all.deb ...
- 正在解包 python-colorama-whl (0.2.5-0.1ubuntu2) ...
- 正在选中未选择的软件包 python-distlib-whl。
- 正准备解包 .../python-distlib-whl_0.1.8-1ubuntu1_all.deb ...
- 正在解包 python-distlib-whl (0.1.8-1ubuntu1) ...
- 正在选中未选择的软件包 python-html5lib-whl。
- 正准备解包 .../python-html5lib-whl_0.999-3~ubuntu1_all.deb ...
- 正在解包 python-html5lib-whl (0.999-3~ubuntu1) ...
- 正在选中未选择的软件包 python-six-whl。
- 正准备解包 .../python-six-whl_1.5.2-1ubuntu1_all.deb ...
- 正在解包 python-six-whl (1.5.2-1ubuntu1) ...
- 正在选中未选择的软件包 python-urllib3-whl。
- 正准备解包 .../python-urllib3-whl_1.7.1-1ubuntu4_all.deb ...
- 正在解包 python-urllib3-whl (1.7.1-1ubuntu4) ...
- 正在选中未选择的软件包 python-requests-whl。
- 正准备解包 .../python-requests-whl_2.2.1-1ubuntu0.3_all.deb ...
- 正在解包 python-requests-whl (2.2.1-1ubuntu0.3) ...
- 正在选中未选择的软件包 python-setuptools-whl。
- 正准备解包 .../python-setuptools-whl_3.3-1ubuntu2_all.deb ...
- 正在解包 python-setuptools-whl (3.3-1ubuntu2) ...
- 正在选中未选择的软件包 python-pip-whl。
- 正准备解包 .../python-pip-whl_1.5.4-1ubuntu3_all.deb ...
- 正在解包 python-pip-whl (1.5.4-1ubuntu3) ...
- 正在选中未选择的软件包 python3-colorama。
- 正准备解包 .../python3-colorama_0.2.5-0.1ubuntu2_all.deb ...
- 正在解包 python3-colorama (0.2.5-0.1ubuntu2) ...
- 正在选中未选择的软件包 python3.4-dev。
- 正准备解包 .../python3.4-dev_3.4.3-1ubuntu1~14.04.3_amd64.deb ...
- 正在解包 python3.4-dev (3.4.3-1ubuntu1~14.04.3) ...
- 正在选中未选择的软件包 python3-dev。
- 正准备解包 .../python3-dev_3.4.0-0ubuntu2_amd64.deb ...
- 正在解包 python3-dev (3.4.0-0ubuntu2) ...
- 正在选中未选择的软件包 python3-distlib。
- 正准备解包 .../python3-distlib_0.1.8-1ubuntu1_all.deb ...
- 正在解包 python3-distlib (0.1.8-1ubuntu1) ...
- 正在选中未选择的软件包 python3-html5lib。
- 正准备解包 .../python3-html5lib_0.999-3~ubuntu1_all.deb ...
- 正在解包 python3-html5lib (0.999-3~ubuntu1) ...
- 正在选中未选择的软件包 python3-setuptools。
- 正准备解包 .../python3-setuptools_3.3-1ubuntu2_all.deb ...
- 正在解包 python3-setuptools (3.3-1ubuntu2) ...
- 正在选中未选择的软件包 python3-pip。
- 正准备解包 .../python3-pip_1.5.4-1ubuntu3_all.deb ...
- 正在解包 python3-pip (1.5.4-1ubuntu3) ...
- 正在选中未选择的软件包 python3-wheel。
- 正准备解包 .../python3-wheel_0.24.0-1~ubuntu1_all.deb ...
- 正在解包 python3-wheel (0.24.0-1~ubuntu1) ...
- 正在处理用于 man-db (2.6.7.1-1ubuntu1) 的触发器 ...
- 正在处理用于 gnome-menus (3.10.1-0ubuntu2) 的触发器 ...
- 正在处理用于 desktop-file-utils (0.22-1ubuntu1) 的触发器 ...
- 正在处理用于 bamfdaemon (0.5.1+14.04.20140409-0ubuntu1) 的触发器 ...
- Rebuilding /usr/share/applications/bamf-2.index...
- 正在处理用于 mime-support (3.54ubuntu1.1) 的触发器 ...
- 正在设置 python3-urllib3 (1.7.1-1ubuntu4) ...
- 正在设置 libpython3.4-minimal:amd64 (3.4.3-1ubuntu1~14.04.3) ...
- 正在设置 libpython3.4-stdlib:amd64 (3.4.3-1ubuntu1~14.04.3) ...
- 正在设置 libpython3.4:amd64 (3.4.3-1ubuntu1~14.04.3) ...
- 正在设置 python3.4-minimal (3.4.3-1ubuntu1~14.04.3) ...
- 正在设置 python3.4 (3.4.3-1ubuntu1~14.04.3) ...
- 正在设置 libpython3.4-dev:amd64 (3.4.3-1ubuntu1~14.04.3) ...
- 正在设置 libpython3-dev:amd64 (3.4.0-0ubuntu2) ...
- 正在设置 python-chardet-whl (2.2.1-2~ubuntu1) ...
- 正在设置 python-colorama-whl (0.2.5-0.1ubuntu2) ...
- 正在设置 python-distlib-whl (0.1.8-1ubuntu1) ...
- 正在设置 python-html5lib-whl (0.999-3~ubuntu1) ...
- 正在设置 python-six-whl (1.5.2-1ubuntu1) ...
- 正在设置 python-urllib3-whl (1.7.1-1ubuntu4) ...
- 正在设置 python-requests-whl (2.2.1-1ubuntu0.3) ...
- 正在设置 python-setuptools-whl (3.3-1ubuntu2) ...
- 正在设置 python-pip-whl (1.5.4-1ubuntu3) ...
- 正在设置 python3-colorama (0.2.5-0.1ubuntu2) ...
- 正在设置 python3.4-dev (3.4.3-1ubuntu1~14.04.3) ...
- 正在设置 python3-dev (3.4.0-0ubuntu2) ...
- 正在设置 python3-distlib (0.1.8-1ubuntu1) ...
- 正在设置 python3-html5lib (0.999-3~ubuntu1) ...
- 正在设置 python3-setuptools (3.3-1ubuntu2) ...
- 正在设置 python3-pip (1.5.4-1ubuntu3) ...
- 正在设置 python3-wheel (0.24.0-1~ubuntu1) ...
- 正在处理用于 libc-bin (2.19-0ubuntu6.6) 的触发器 ...
- senrsl@senrsl-T540p:~/test/python3$
报错了啊
- senrsl@senrsl-T540p:~/test/python3$ pip3 install Pillow
- Downloading/unpacking Pillow
- Downloading Pillow-3.2.0.zip (10.5MB): 10.5MB downloaded
- Running setup.py (path:/tmp/pip_build_senrsl/Pillow/setup.py) egg_info for package Pillow
- warning: no files found matching '*.sh'
- no previously-included directories found matching 'docs/_static'
- warning: no previously-included files found matching '.coveragerc'
- warning: no previously-included files found matching '.editorconfig'
- warning: no previously-included files found matching '.landscape.yaml'
- warning: no previously-included files found matching 'appveyor.yml'
- warning: no previously-included files found matching 'build_children.sh'
- warning: no previously-included files found matching 'tox.ini'
- warning: no previously-included files matching '.git*' found anywhere in distribution
- warning: no previously-included files matching '*.pyc' found anywhere in distribution
- warning: no previously-included files matching '*.so' found anywhere in distribution
- Installing collected packages: Pillow
- Running setup.py install for Pillow
- warning: no files found matching '*.sh'
- no previously-included directories found matching 'docs/_static'
- warning: no previously-included files found matching '.coveragerc'
- warning: no previously-included files found matching '.editorconfig'
- warning: no previously-included files found matching '.landscape.yaml'
- warning: no previously-included files found matching 'appveyor.yml'
- warning: no previously-included files found matching 'build_children.sh'
- warning: no previously-included files found matching 'tox.ini'
- warning: no previously-included files matching '.git*' found anywhere in distribution
- warning: no previously-included files matching '*.pyc' found anywhere in distribution
- warning: no previously-included files matching '*.so' found anywhere in distribution
- Traceback (most recent call last):
- File "<string>", line 1, in <module>
- File "/tmp/pip_build_senrsl/Pillow/setup.py", line 767, in <module>
- zip_safe=not debug_build(), )
- File "/usr/lib/python3.4/distutils/core.py", line 148, in setup
- dist.run_commands()
- File "/usr/lib/python3.4/distutils/dist.py", line 955, in run_commands
- self.run_command(cmd)
- File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
- cmd_obj.run()
- File "/usr/lib/python3/dist-packages/setuptools/command/install.py", line 53, in run
- return _install.run(self)
- File "/usr/lib/python3.4/distutils/command/install.py", line 583, in run
- self.run_command('build')
- File "/usr/lib/python3.4/distutils/cmd.py", line 313, in run_command
- self.distribution.run_command(command)
- File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
- cmd_obj.run()
- File "/usr/lib/python3.4/distutils/command/build.py", line 126, in run
- self.run_command(cmd_name)
- File "/usr/lib/python3.4/distutils/cmd.py", line 313, in run_command
- self.distribution.run_command(command)
- File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
- cmd_obj.run()
- File "/usr/lib/python3.4/distutils/command/build_ext.py", line 339, in run
- self.build_extensions()
- File "/tmp/pip_build_senrsl/Pillow/setup.py", line 512, in build_extensions
- ' using --disable-%s, aborting' % (f, f))
- ValueError: jpeg is required unless explicitly disabled using --disable-jpeg, aborting
- Complete output from command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_senrsl/Pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-9zk2hx82-record/install-record.txt --single-version-externally-managed --compile:
- running install
- running build
- running build_py
- creating build
- creating build/lib.linux-x86_64-3.4
- creating build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageStat.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/IcnsImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/JpegImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImtImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/XbmImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/WmfImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageMode.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PpmImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/MpegImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PdfImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/features.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageMorph.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/DcxImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/GdImageFile.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/BufrStubImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImagePalette.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/MspImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageMath.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/JpegPresets.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/Image.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PcxImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/XpmImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageDraw2.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageWin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ExifTags.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/__init__.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/OleFileIO.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/EpsImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageFilter.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/TiffTags.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/IcoImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PalmImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/Jpeg2KImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/WebPImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageShow.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/McIdasImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/TgaImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/SunImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PyAccess.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PngImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PixarImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/WalImageFile.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/BmpImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageQt.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/GifImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageSequence.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageColor.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/FliImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageChops.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/BdfFontFile.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PsdImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageTransform.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/GbrImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageDraw.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/FontFile.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/DdsImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/_binary.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PcdImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/XVThumbImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImagePath.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageGrab.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/IptcImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/FitsStubImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ContainerIO.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/GribStubImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/SpiderImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/Hdf5StubImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageCms.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PcfFontFile.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/FpxImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageTk.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/GimpPaletteFile.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/_util.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/MicImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageOps.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/GimpGradientFile.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageEnhance.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageFont.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/ImageFile.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/CurImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/TarIO.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/TiffImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/SgiImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/MpoImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PaletteFile.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/PSDraw.py -> build/lib.linux-x86_64-3.4/PIL
- copying PIL/FtexImagePlugin.py -> build/lib.linux-x86_64-3.4/PIL
- running egg_info
- writing dependency_links to Pillow.egg-info/dependency_links.txt
- writing Pillow.egg-info/PKG-INFO
- writing top-level names to Pillow.egg-info/top_level.txt
- warning: manifest_maker: standard file '-c' not found
- reading manifest file 'Pillow.egg-info/SOURCES.txt'
- reading manifest template 'MANIFEST.in'
- warning: no files found matching '*.sh'
- no previously-included directories found matching 'docs/_static'
- warning: no previously-included files found matching '.coveragerc'
- warning: no previously-included files found matching '.editorconfig'
- warning: no previously-included files found matching '.landscape.yaml'
- warning: no previously-included files found matching 'appveyor.yml'
- warning: no previously-included files found matching 'build_children.sh'
- warning: no previously-included files found matching 'tox.ini'
- warning: no previously-included files matching '.git*' found anywhere in distribution
- warning: no previously-included files matching '*.pyc' found anywhere in distribution
- warning: no previously-included files matching '*.so' found anywhere in distribution
- writing manifest file 'Pillow.egg-info/SOURCES.txt'
- copying PIL/OleFileIO-README.md -> build/lib.linux-x86_64-3.4/PIL
- running build_ext
- Traceback (most recent call last):
- File "<string>", line 1, in <module>
- File "/tmp/pip_build_senrsl/Pillow/setup.py", line 767, in <module>
- zip_safe=not debug_build(), )
- File "/usr/lib/python3.4/distutils/core.py", line 148, in setup
- dist.run_commands()
- File "/usr/lib/python3.4/distutils/dist.py", line 955, in run_commands
- self.run_command(cmd)
- File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
- cmd_obj.run()
- File "/usr/lib/python3/dist-packages/setuptools/command/install.py", line 53, in run
- return _install.run(self)
- File "/usr/lib/python3.4/distutils/command/install.py", line 583, in run
- self.run_command('build')
- File "/usr/lib/python3.4/distutils/cmd.py", line 313, in run_command
- self.distribution.run_command(command)
- File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
- cmd_obj.run()
- File "/usr/lib/python3.4/distutils/command/build.py", line 126, in run
- self.run_command(cmd_name)
- File "/usr/lib/python3.4/distutils/cmd.py", line 313, in run_command
- self.distribution.run_command(command)
- File "/usr/lib/python3.4/distutils/dist.py", line 974, in run_command
- cmd_obj.run()
- File "/usr/lib/python3.4/distutils/command/build_ext.py", line 339, in run
- self.build_extensions()
- File "/tmp/pip_build_senrsl/Pillow/setup.py", line 512, in build_extensions
- ' using --disable-%s, aborting' % (f, f))
- ValueError: jpeg is required unless explicitly disabled using --disable-jpeg, aborting
- ----------------------------------------
- Cleaning up...
- Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_senrsl/Pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-9zk2hx82-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_senrsl/Pillow
- Storing debug log for failure in /home/senrsl/.pip/pip.log
- senrsl@senrsl-T540p:~/test/python3$
然后就可以用图片处理的库了:
- senrsl@senrsl-T540p:~/test/python3$ sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev \
- > libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk
- 正在读取软件包列表... 完成
- 正在分析软件包的依赖关系树
- 正在读取状态信息... 完成
- zlib1g-dev 已经是最新的版本了。
- 将会安装下列额外的软件包:
- libfontconfig1-dev libjbig-dev libjpeg-turbo8-dev liblzma-dev libpng12-0
- libpng12-0:i386 libpng12-dev libtcl8.5 libtiff5-dev libtiffxx5 libtk8.5
- libwebpdemux1 libxft-dev libxrender-dev libxss-dev tcl8.5 tk8.5
- x11proto-render-dev x11proto-scrnsaver-dev
- 建议安装的软件包:
- liblzma-doc tix python-tk-dbg tcl-tclreadline tcl8.5-doc tk8.5-doc
- 下列【新】软件包将被安装:
- libfontconfig1-dev libfreetype6-dev libjbig-dev libjpeg-turbo8-dev
- libjpeg8-dev liblcms2-dev liblzma-dev libpng12-dev libtcl8.5 libtiff4-dev
- libtiff5-dev libtiffxx5 libtk8.5 libwebp-dev libwebpdemux1 libxft-dev
- libxrender-dev libxss-dev python-tk tcl8.5 tcl8.5-dev tk8.5 tk8.5-dev
- x11proto-render-dev x11proto-scrnsaver-dev
- 下列软件包将被升级:
- libpng12-0 libpng12-0:i386
- 升级了 2 个软件包,新安装了 25 个软件包,要卸载 0 个软件包,有 343 个软件包未被升级。
- 需要下载 10.5 MB 的软件包。
- 解压缩后会消耗掉 28.5 MB 的额外空间。
- 您希望继续执行吗? [Y/n] Y
- 获取:1 http://archive.ubuntu.com/ubuntu/ trusty/main libtcl8.5 amd64 8.5.15-2ubuntu1 [684 kB]
- 获取:2 http://security.ubuntu.com/ubuntu/ trusty-security/main libpng12-0 i386 1.2.50-1ubuntu2.14.04.2 [119 kB]
- 获取:3 http://security.ubuntu.com/ubuntu/ trusty-security/main libpng12-0 amd64 1.2.50-1ubuntu2.14.04.2 [118 kB]
- 获取:4 http://security.ubuntu.com/ubuntu/ trusty-security/main libjbig-dev amd64 2.0-2ubuntu4.1 [6,268 B]
- 获取:5 http://security.ubuntu.com/ubuntu/ trusty-security/main libpng12-dev amd64 1.2.50-1ubuntu2.14.04.2 [206 kB]
- 获取:6 http://archive.ubuntu.com/ubuntu/ trusty/main libtk8.5 amd64 8.5.15-2ubuntu3 [641 kB]
- 获取:7 http://security.ubuntu.com/ubuntu/ trusty-security/main libfreetype6-dev amd64 2.5.2-1ubuntu2.5 [621 kB]
- 获取:8 http://archive.ubuntu.com/ubuntu/ trusty/main libwebpdemux1 amd64 0.4.0-4 [7,836 B]
- 获取:9 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libfontconfig1-dev amd64 2.11.0-0ubuntu4.1 [664 kB]
- 获取:10 http://security.ubuntu.com/ubuntu/ trusty-security/main libxrender-dev amd64 1:0.9.8-1build0.14.04.1 [23.8 kB]
- 获取:11 http://archive.ubuntu.com/ubuntu/ trusty/main libjpeg-turbo8-dev amd64 1.3.0-0ubuntu2 [242 kB]
- 获取:12 http://archive.ubuntu.com/ubuntu/ trusty/main libjpeg8-dev amd64 8c-2ubuntu8 [1,552 B]
- 获取:13 http://archive.ubuntu.com/ubuntu/ trusty/main liblcms2-dev amd64 2.5-0ubuntu4 [5,097 kB]
- 获取:14 http://archive.ubuntu.com/ubuntu/ trusty/main liblzma-dev amd64 5.1.1alpha+20120614-2ubuntu2 [137 kB]
- 获取:15 http://archive.ubuntu.com/ubuntu/ trusty/main x11proto-render-dev all 2:0.11.1-2 [20.1 kB]
- 获取:16 http://archive.ubuntu.com/ubuntu/ trusty/main libxft-dev amd64 2.3.1-2 [45.8 kB]
- 获取:17 http://archive.ubuntu.com/ubuntu/ trusty/main x11proto-scrnsaver-dev all 1.2.2-1 [25.0 kB]
- 获取:18 http://archive.ubuntu.com/ubuntu/ trusty/main libxss-dev amd64 1:1.2.2-1 [12.7 kB]
- 获取:19 http://archive.ubuntu.com/ubuntu/ trusty/main python-tk amd64 2.7.5-1ubuntu1 [23.6 kB]
- 获取:20 http://archive.ubuntu.com/ubuntu/ trusty/main tcl8.5 amd64 8.5.15-2ubuntu1 [13.9 kB]
- 获取:21 http://archive.ubuntu.com/ubuntu/ trusty/main tcl8.5-dev amd64 8.5.15-2ubuntu1 [659 kB]
- 获取:22 http://archive.ubuntu.com/ubuntu/ trusty/main tk8.5 amd64 8.5.15-2ubuntu3 [12.0 kB]
- 获取:23 http://archive.ubuntu.com/ubuntu/ trusty/main tk8.5-dev amd64 8.5.15-2ubuntu3 [646 kB]
- 获取:24 http://archive.ubuntu.com/ubuntu/ trusty/main libwebp-dev amd64 0.4.0-4 [203 kB]
- 错误 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libtiffxx5 amd64 4.0.3-7ubuntu0.3
- 404 Not Found [IP: 91.189.88.161 80]
- 错误 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libtiff5-dev amd64 4.0.3-7ubuntu0.3
- 404 Not Found [IP: 91.189.88.161 80]
- 错误 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libtiff4-dev amd64 4.0.3-7ubuntu0.3
- 404 Not Found [IP: 91.189.88.161 80]
- 下载 10.2 MB,耗时 1分 28秒 (116 kB/s)
- E: 无法下载 http://archive.ubuntu.com/ubuntu/pool/main/t/tiff/libtiffxx5_4.0.3-7ubuntu0.3_amd64.deb 404 Not Found [IP: 91.189.88.161 80]
- E: 无法下载 http://archive.ubuntu.com/ubuntu/pool/main/t/tiff/libtiff5-dev_4.0.3-7ubuntu0.3_amd64.deb 404 Not Found [IP: 91.189.88.161 80]
- E: 无法下载 http://archive.ubuntu.com/ubuntu/pool/main/t/tiff/libtiff4-dev_4.0.3-7ubuntu0.3_amd64.deb 404 Not Found [IP: 91.189.88.161 80]
- E: 有几个软件包无法下载,您可以运行 apt-get update 或者加上 --fix-missing 的选项再试试?
- senrsl@senrsl-T540p:~/test/python3$
- senrsl@senrsl-T540p:~/test/python3$ sudo apt-get update
- senrsl@senrsl-T540p:~/test/python3$ sudo apt-get install libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk
- 正在读取软件包列表... 完成
- 正在分析软件包的依赖关系树
- 正在读取状态信息... 完成
- zlib1g-dev 已经是最新的版本了。
- 将会安装下列额外的软件包:
- libfontconfig1-dev libjbig-dev libjpeg-turbo8-dev liblcms2-2 liblcms2-2:i386
- liblzma-dev libpng12-0 libpng12-0:i386 libpng12-dev libtcl8.5 libtiff5
- libtiff5:i386 libtiff5-dev libtiffxx5 libtk8.5 libwebpdemux1 libxft-dev
- libxrender-dev libxss-dev tcl8.5 tk8.5 x11proto-render-dev
- x11proto-scrnsaver-dev
- 建议安装的软件包:
- liblcms2-utils liblcms2-utils:i386 liblzma-doc tix python-tk-dbg
- tcl-tclreadline tcl8.5-doc tk8.5-doc
- 下列【新】软件包将被安装:
- libfontconfig1-dev libfreetype6-dev libjbig-dev libjpeg-turbo8-dev
- libjpeg8-dev liblcms2-dev liblzma-dev libpng12-dev libtcl8.5 libtiff4-dev
- libtiff5-dev libtiffxx5 libtk8.5 libwebp-dev libwebpdemux1 libxft-dev
- libxrender-dev libxss-dev python-tk tcl8.5 tcl8.5-dev tk8.5 tk8.5-dev
- x11proto-render-dev x11proto-scrnsaver-dev
- 下列软件包将被升级:
- liblcms2-2 liblcms2-2:i386 libpng12-0 libpng12-0:i386 libtiff5 libtiff5:i386
- 升级了 6 个软件包,新安装了 25 个软件包,要卸载 0 个软件包,有 408 个软件包未被升级。
- 需要下载 5,914 kB/11.0 MB 的软件包。
- 解压缩后会消耗掉 28.6 MB 的额外空间。
- 您希望继续执行吗? [Y/n] Y
- 。。。。
- senrsl@senrsl-T540p:~/test/python3$ pip3 install Pillow
- 。。。。
- creating /usr/local/lib/python3.4/dist-packages/PIL
- error: could not create '/usr/local/lib/python3.4/dist-packages/PIL': Permission denied
- ----------------------------------------
- Cleaning up...
- Command /usr/bin/python3 -c "import setuptools, tokenize;__file__='/tmp/pip_build_senrsl/Pillow/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-a1gsc85i-record/install-record.txt --single-version-externally-managed --compile failed with error code 1 in /tmp/pip_build_senrsl/Pillow
- Storing debug log for failure in /home/senrsl/.pip/pip.log
- senrsl@senrsl-T540p:~/test/python3$ sudo pip3 install Pillow
- 。。。。
- Successfully installed Pillow
- Cleaning up...
- senrsl@senrsl-T540p:~/test/python3$
- 哎,我好无聊啊
- senrsl@senrsl-T540p:~/test/python3$ python3
- Python 3.4.3 (default, Oct 14 2015, 20:28:29)
- [GCC 4.8.4] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>> from PIL import Image;
- >>> im = Image.open("111111111.png");
- >>> print(im.format,im.size,im.mode);
- PNG (964, 787) RGB
- >>> im.thumbnail((50,40));
- >>> im.save("thumb.jpg","JPEG");
- >>> exit();
- senrsl@senrsl-T540p:~/test/python3$ ll
- 总用量 164
- drwxrwxr-x 3 senrsl senrsl 4096 6月 20 17:33 ./
- drwxrwxr-x 10 senrsl senrsl 4096 6月 14 11:12 ../
- -rw-rw-r-- 1 senrsl senrsl 136100 2月 17 14:57 111111111.png
- -rwxrwxr-x 1 senrsl senrsl 332 6月 20 16:51 helloWorld01.py*
- -rwxrwxr-x 1 senrsl senrsl 94 6月 14 18:08 helloWorld.py*
- -rwxrwxr-x 1 senrsl senrsl 71 6月 14 18:07 helloWorld.py~*
- drwxrwxr-x 2 senrsl senrsl 4096 6月 20 16:55 __pycache__/
- -rw-rw-r-- 1 senrsl senrsl 1214 6月 20 17:33 thumb.jpg
- senrsl@senrsl-T540p:~/test/python3$
环境变量:
- >>> import sys;
- >>> sys.path;
- ['', '/usr/lib/python3.4', '/usr/lib/python3.4/plat-x86_64-linux-gnu', '/usr/lib/python3.4/lib-dynload', '/usr/local/lib/python3.4/dist-packages', '/usr/lib/python3/dist-packages']
- >>>
8,面向对象
OOP:Object Oriented Programming
封装,继承,多态
1)类Class/实例Instance
类是抽象的模板;
实例是根据类创建出来的一个个具体的对象;
定义一个类:
类名首字母大写,所有类都继承于object类
- >>> class Student(object):
- ... pass
- ...
- >>>
从这个类创建一个实例b:
- >>> b = Student();
- >>> b
- <__main__.Student object at 0x7fe0fe1fd588>
- >>> Student
- <class '__main__.Student'>
- >>>
带参数的构造函数:
2)变量私有化
- >>> class Student01(object):
- ... def __init__(self,name,age):
- ... self.name=name;
- ... self.age = age;
- ...
- >>> c = Student01("小A",100);
- >>> c.name;
- '小A'
- >>> c.age;
- 100
- >>>
格式为 __xxx为私有变量,外部无法访问;
格式为__xxx__为特殊变量;
格式为_xxx为可以访问但请不要访问的私有变量;
不要在意那些细节
- >>> class Student02(object):
- ... def __init__(self,name,age):
- ... self.__name=name;
- ... self.__age=age;
- ... def print_info(self):
- ... print("信息 %s 是%s" % (self.__name,self.__age));
- ... def get_name(self):
- ... return self.__name;
- ... def get_age(self):
- ... return self.__age;
- ... def set_score(self,score):
- ... self.__age = score;
- ... def set_name(self,name):
- ... self.__name = name;
- ...
- >>> d = Student02("小B",11);
- >>> d.print_info();
- 信息 小B 是11
- >>> d.get_name();
- '小B'
- >>> d.set_name("小小B");
- >>> d.get_name();
- '小小B'
- >>> d.print_info();
- 信息 小小B 是11
- >>>
3)继承和多态
鸭子类型
4)获取对象信息
①使用type()
②isinstance()
- >>> type(1);
- <class 'int'>
- >>> type("1");
- <class 'str'>
- >>> type(abs);
- <class 'builtin_function_or_method'>
- >>> type(d);
- <class '__main__.Student02'>
- >>>
- >>> import types;
- >>> def fn():
- ... pass;
- ...
- >>> type(fn) == types.FunctionType;
- True
- >>> type(abs) == types.BuiltinFunctionType;
- True
- >>> type(lambda x : x) == types.LambdaType;
- True
- >>> type(x for x in range(10)) == types.GeneratorType;
- True
- >>>
③dir()
- >>> isinstance(d,Student02);
- True
- >>> isinstance(d,object);
- True
- >>> isinstance(1,object);
- True
- >>> isinstance(1,int);
- True
- >>> isinstance([1,2,3],(list,tuple));
- True
- >>>
获取一个对象的所有属性和方法
5)实例属性和类属性
- >>> dir("ABC");
- ['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
- >>> len("ABC");
- 3
- >>> "ABC".__len__();
- 3
- >>>
类本身属性
看起来像是static
- >>> class Student03(object):
- ... name = "Student";
- ...
- >>> print(Student03.name);
- Student
- >>>
8.1 面向对象高级
1)使用__slots__限制动态绑定
①动态绑定属性
- >>> class Student(object):
- ... pass;
- ...
- >>> s = Student();
- >>> s.name = "fuck";
- >>> print(s.name);
- fuck
- >>>
②动态绑定方法
a)给实例动态绑定一个方法,作用于单个实例:
- >>> def set_age(self,age):
- ... self.age = age;
- ...
- >>> from types import MethodType;
- >>> s.set_age = MethodType(set_age,s);
- >>> s.set_age(111);
- >>> s.age
- 111
- >>>
b)给class动态绑定一个方法,作用于全部实例:
- >>> Student.set_score = set_score;
- >>> s.set_score(100);
- >>> s.score
- 100
- >>>
③使用__slots限制绑定
限制绑定只对当前类有效,对子类无效
- >>> class Student(object):
- ... __slots__ = ("name","age"); # 用tuple定义允许绑定的属性名称
- ...
- >>> s = Student();
- >>> s.name = "a";
- >>> s.age = 2;
- >>> s.score = 1;
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- AttributeError: 'Student' object has no attribute 'score'
- >>>
- >>> class Student01(Student):
- ... pass;
- ...
- >>> s01 = Student01();
- >>> s01.score = 1;
- >>>
2)使用@property装饰器把一个方法变成属性调用
birth是可读写,age是只读属性;
- >>> class Student02(object):
- ... @property
- ... def birth(self):
- ... return self._birth;
- ... @birth.setter
- ... def birth(self,value):
- ... self._birth = value;
- ... @property
- ... def age(self):
- ... return 2015-self._birth;
- ...
- >>> b = Student02();
- >>> b.birth = 1900;
- >>> b.birth;
- 1900
- >>> b.age;
- 115
- >>>
3)多重继承
继承一般都是单一继承,一个继承一个
Mixln设计
- >>> class Animal(object):
- ... pass;
- ...
- >>> class Mammal(Animal):
- ... pass;
- ...
- >>> class RunableMixln(object):
- ... pass;
- ...
- >>> class FlyableMixln(object):
- ... pass;
- ...
- >>> class Dog(Mammal,RunableMixln,FlyableMixln):
- ... pass;
- ...
- >>>
4)定制类
特殊用途的函数,可以用来定制类
所有可定制方法:https://docs.python.org/3/reference/datamodel.html#special- method-names
其中__str__作用于print(Student("啊"));
- >>> class Student(object):
- ... def __init__(self,name):
- ... self.name = name;
- ... def __str__(self):
- ... return "Student object has name:%s!" % self.name;
- ... __repr__ = __str__;
- ...
- >>> print(Student("啊"));
- Student object has name:啊!
- >>> s = Student("呃");
- >>> s
- Student object has name:呃!
- >>>
其中__repr__作用于s;
上面这俩就是.toString();
定义类支持迭代:
- >>> class Fib(object):
- ... def __init__(self,max):
- ... self.a,self.b = 0,1;
- ... self._max = max;
- ... def __iter__(self):
- ... return self;
- ... def __next__(self):
- ... self.a,self.b = self.b,self.a+self.b;
- ... if self.a > self._max:
- ... raise StopIteration();
- ... return self.a;
- ... def __getitem__(self,n):
- ... if isinstance(n,int): # n是索引
- ... a,b = 1,1;
- ... for x in range(n):
- ... a,b = b,a+b;
- ... return a;
- ... if isinstance(n,slice): # n是切片
- ... start = n.start;
- ... stop = n.stop;
- ... if start is None:
- ... start = 0;
- ... a,b = 1,1;
- ... L = [];
- ... for x in range(stop):
- ... if x >= start:
- ... L.append(a);
- ... a,b = b,a+b;
- ... return L;
- ...
- >>> f = Fib(100);
- >>> f[0]
- 1
- >>> f[10]
- 89
- >>> f[0:5];
- [1, 1, 2, 3, 5]
- >>> f[:10]
- [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
- >>>
其中__iter__是迭代支撑;
其中__next__是迭代的每一步;
其中__getitem__是支持下标跟切片;
可以动态设置属性:
- >>> class Student(object):
- ... def __init__(self):
- ... self.name = "名字";
- ... def __getattr__(self,attr):
- ... if attr == "age":
- ... return 100;
- ... elif attr == "score":
- ... return lambda:25;
- ... raise AttributeError("没有no attr %s !" % attr);
- ...
- >>> s = Student();
- >>> s.name
- '名字'
- >>> s.age
- 100
- >>> s.score();
- 25
- >>> s.aaa
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "<stdin>", line 9, in __getattr__
- AttributeError: 没有no attr aaa !
- >>>
判断一个对象是不是可以被调用:
- >>> class Student(object):
- ... def __init__(self,name):
- ... self.name = name;
- ... def __call__(self):
- ... print("name 是 %s!" % self.name);
- ...
- >>> s = Student("啊啊啊");
- >>> s()
- name 是 啊啊啊!
- >>>
- >>> callable(Student("啊啊啊"));
- True
- >>> callable(max);
- True
- >>> callable([1,2,3]);
- False
- >>>
5)枚举
两种方式
- >>> from enum import Enum;
- >>> Month = Enum("Month",("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"));
- >>> for name,member in Month.__members__.items():
- ... print(name,"=>",member,",",member.value);
- ...
- Jan => Month.Jan , 1
- Feb => Month.Feb , 2
- Mar => Month.Mar , 3
- Apr => Month.Apr , 4
- May => Month.May , 5
- Jun => Month.Jun , 6
- Jul => Month.Jul , 7
- Aug => Month.Aug , 8
- Sep => Month.Sep , 9
- Oct => Month.Oct , 10
- Nov => Month.Nov , 11
- Dec => Month.Dec , 12
- >>>
- >>> from enum import Enum,unique;
- >>> @unique
- ... class Weekday(Enum):
- ... Sun = 0;
- ... Mon = 1;
- ... Tue = 2;
- ... Wed = 3;
- ... Thu = 4;
- ... Fri = 5;
- ... Sat = 6;
- ...
- >>> day1 = Weekday.Mon;
- >>> print(day1);
- Weekday.Mon
- >>> print(Weekday.Tue);
- Weekday.Tue
- >>> print(Weekday["Tue"]);
- Weekday.Tue
- >>> print(Weekday.Tue.value);
- 2
- >>> for name,member in Weekday.__members__.items():
- ... print(name,"->",member);
- ...
- Sun -> Weekday.Sun
- Mon -> Weekday.Mon
- Tue -> Weekday.Tue
- Wed -> Weekday.Wed
- Thu -> Weekday.Thu
- Fri -> Weekday.Fri
- Sat -> Weekday.Sat
- >>>
6)动态创建类
①使用type动态创建类
动态创建一个class
- >>> class Hello(object):
- ... def hello(self,name="world"):
- ... print("Hello,%s!" % name);
- ...
- >>> h = Hello();
- >>> h.hello();
- Hello,world!
- >>> print(type(Hello));
- <class 'type'>
- >>> print(type(h));
- <class '__main__.Hello'>
- >>>
- >>> def fn(self,name="word"):
- ... print("hello,%s !" % name);
- ...
- >>> Hello = type("Hello",(object,),dict(hello=fn));
- >>> h = Hello();
- >>> h.hello();
- hello,word !
- >>> print(type(Hello));
- <class 'type'>
- >>> print(type(h));
- <class '__main__.Hello'>
- >>>
- >>> Hello1 = type("Hello2",(object,),dict(hello=fn));
- >>> h1 = Hello1();
- >>> print(type(Hello1));
- <class 'type'>
- >>> print(type(Hello2));
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- NameError: name 'Hello2' is not defined
- >>> print(type(h1));
- <class '__main__.Hello2'>
- >>>
需要传入三个参数:
- Hello1 = type("Hello2",(object,),dict(hello=fn));
- 指向变量 = type("类名",(继承的第一个父类,继承的第二个父类,),dict(第一个函数=第一个函数绑定的方法));
上面那个dict里面用冒号发现会报错。
②metaclass元类
一个demo:
其中__new__()方法的参数:
- >>> class ListMetaclass(type):
- ... def __new__(cls,name,bases,attrs):
- ... attrs["add"] = lambda self,value : self.append(value);
- ... return type.__new__(cls,name,bases,attrs);
- ...
- >>> class MyList(list,metaclass=ListMetaclass):
- ... pass;
- ...
- >>> L = MyList();
- >>> L.add(1);
- >>> L
- [1]
- >>>
- def __new__(当前准备创建类的对象,类名,父类集合,类的方法集合);
使用metaclass构建一个简单的ORM架构
ORM为对象-关系映射,Object Relational Mapping.
不明觉厉。。。。
- >>> class Filed(object):
- ... def __init__(self,name,column_type):
- ... self.name = name;
- ... self.column_type = column_type;
- ... def __str__(self):
- ... return "<%s : %s>" % (self.__class__.__name__,self.name);
- ...
- >>> class StringFiled(Filed):
- ... def __init__(self,name):
- ... super(StringFiled,self).__init__(name,"varchar(100)");
- ...
- >>> class IntegerFiled(Filed):
- ... def __init__(self,name):
- ... super(IntegerFiled,self).__init__(name,"bigint");
- ...
- >>> class ModelMetaclass(type):
- ... def __new__(cls,name,bases,attrs):
- ... if name == "Model":
- ... return type.__new__(cls,name,bases,attrs);
- ... print("发现model:%s" % name);
- ... mappings = dict();
- ... for k,v in attrs.items():
- ... if isinstance(v,Filed):
- ... print("发现映射关系%s=====>%s" % (k,v));
- ... mappings[k] = v;
- ... for k in mappings.keys():
- ... attrs.pop(k);
- ... attrs["__mappings__"] = mappings;#保存属性和列的映射关系
- ... attrs["__table__"] = name; # 假设表名和类名一致
- ... return type.__new__(cls,name,bases,attrs);
- ...
- >>> class Model(dict,metaclass=ModelMetaclass):
- ... def __init__(self,**kw):
- ... super(Model,self).__init__(**kw);
- ... def __getattr__(self,key):
- ... try:
- ... return self[key];
- ... except KeyError:
- ... raise AttributeError("对象Model没这个属性%s" % key);
- ... def __setattr__(self,key,value):
- ... self[key] = value;
- ... def save(self):
- ... fields = [];
- ... params = [];
- ... args = [];
- ... for k,v in self.__mappings__.items():
- ... fields.append(v.name);
- ... params.append("?");
- ... args.append(getattr(self,k,None));
- ... sql = "insert into %s (%s) values (%s)" % (self.__table__,",".join(fields),",".join(params));
- ... print("SQL语句 %s" % sql);
- ... print("ARGS参数 %s " % str(args));
- ...
- >>> class User(Model):
- ... id = IntegerFiled("id");
- ... name = StringFiled("username");
- ... email = StringFiled("email");
- ... password = StringFiled("password");
- ...
- 发现model:User
- 发现映射关系id=====><IntegerFiled : id>
- 发现映射关系name=====><StringFiled : username>
- 发现映射关系email=====><StringFiled : email>
- 发现映射关系password=====><StringFiled : password>
- >>> u = User(id = 12345,name="fuck",email= "fuck@fuck.org",password="fffuck");
- >>> u.save();
- SQL语句 insert into User (email,password,id,username) values (?,?,?,?)
- ARGS参数 ['fuck@fuck.org', 'fffuck', 12345, 'fuck']
- >>>
9,Exception/Debug/UnitTest
1)异常
①try-catch-finally
多了个不伦不类的else.
- >>> try:
- ... print("try");
- ... r = 10/int("2");
- ... print("result",r);
- ... except ValueError as e:
- ... print("错误 value:",e);
- ... except ZeroDivisionError as e:
- ... print("除0错误:",e);
- ... else:
- ... print("没有错误");
- ... finally:
- ... print("结束");
- ...
- try
- result 5.0
- 没有错误
- 结束
- >>>
所有的异常都在这https://docs.python.org/3/library/exceptions.html#exception- hierarchy
②堆栈调用
逐层查找错误位置及原因
- >>> def foo(s):
- ... return 10/int(s);
- ...
- >>> def bar(s):
- ... return foo(s)*2;
- ...
- >>> def main():
- ... bar("0");
- ...
- >>> main();
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "<stdin>", line 2, in main
- File "<stdin>", line 2, in bar
- File "<stdin>", line 2, in foo
- ZeroDivisionError: division by zero
- >>>
③日志记录logging
抛了异常后,else也不执行了,这个代码块直接finally然后下个代码块。
- >>> import logging;
- >>> def foo(s):
- ... return 10/int(s);
- ...
- >>> def bar(s):
- ... return foo(s)*2;
- ...
- >>> def main():
- ... try:
- ... bar("0");
- ... except Exception as e:
- ... logging.exception(e);
- ... else:
- ... print("不伦不类");
- ... finally:
- ... print("End");
- ... print("End");
- ...
- >>> main();
- ERROR:root:division by zero
- Traceback (most recent call last):
- File "<stdin>", line 3, in main
- File "<stdin>", line 2, in bar
- File "<stdin>", line 2, in foo
- ZeroDivisionError: division by zero
- End
- End
- >>>
④自定义异常
- >>> class FooErr(ValueError):
- ... pass;
- ...
- >>> def foo(s):
- ... n = int(s);
- ... if n == 0:
- ... raise FooErr("无效值%s" % s);
- ... return 10/n;
- ...
- >>> foo("0");
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "<stdin>", line 4, in foo
- __main__.FooErr: 无效值0
2)debug
①print("xxxxxx");
②assert
可以用在启动的时候python3 -O xx.py来pass断言。
- >>> def foo(s):
- ... n = int(s);
- ... assert n != 0,"n是0";
- ... return 10 / n;
- ...
- >>> foo(0);
- Traceback (most recent call last):
- File "<stdin>", line 1, in <module>
- File "<stdin>", line 3, in foo
- AssertionError: n是0
- >>> foo(3);
- 3.3333333333333335
- >>>
③logging
- >>> import logging;
- >>> logging.basicConfig(level=logging.WARNING);
- >>> def fuck(s):
- ... logging.debug("当前级别是debug:%s" % s);
- ... logging.info("当前级别是info:%s" % s);
- ... logging.warning("当前级别是warning:%s" % s);
- ... logging.error("当前级别是error:%s" % s);
- ...
- >>> fuck("啊不错的风格");
- WARNING:root:当前级别是warning:啊不错的风格
- ERROR:root:当前级别是error:啊不错的风格
- >>>
④pdb
pdb模式下:
【l】查看代码;
【n】单步执行;
【p 变量名】查看变量;
【q】退出;
- senrsl@senrsl-T540p:~/test/python3$ python3 -m pdb helloWorld01.py
- > /home/senrsl/test/python3/helloWorld01.py(4)<module>()
- -> "这是注释"
- (Pdb) n
- > /home/senrsl/test/python3/helloWorld01.py(6)<module>()
- -> __author__ = "senRsl";
- (Pdb) l
- 1 #!/usr/bin/env python3
- 2 # -*- coding:utf-8 -*-
- 3
- 4 "这是注释"
- 5
- 6 -> __author__ = "senRsl";
- 7
- 8 import sys;
- 9
- 10 def test():
- 11 args = sys.argv;
- (Pdb) n
- > /home/senrsl/test/python3/helloWorld01.py(8)<module>()
- -> import sys;
- (Pdb) n
- > /home/senrsl/test/python3/helloWorld01.py(10)<module>()
- -> def test():
- (Pdb) n
- > /home/senrsl/test/python3/helloWorld01.py(19)<module>()
- -> if __name__ == "__main__":
- (Pdb) n
- > /home/senrsl/test/python3/helloWorld01.py(20)<module>()
- -> test();
- (Pdb) n
- 你好啊
- --Return--
- > /home/senrsl/test/python3/helloWorld01.py(20)<module>()->None
- -> test();
- (Pdb) n
- --Return--
- > <string>(1)<module>()->None
- (Pdb) p __author__
- 'senRsl'
- (Pdb) q
- senrsl@senrsl-T540p:~/test/python3$
打断点:
代码中
import pdb;
pdb.set_trace();
代码运行到这里就自动进入pdb了。。。。
附,pdb的命令:
- 命令 解释
- break 或 b 设置断点
- continue 或 c 继续执行程序
- list 或 l 查看当前行的代码段
- step 或 s 进入函数
- return 或 r 执行代码直到从当前函数返回
- exit 或 q 中止并退出
- next 或 n 执行下一行
- p 变量名 打印变量的值
- help 帮助
⑤IDE
一个好用的IDE是多么的重要。
PyCharm:https://www.jetbrains.com/pycharm/
Eclipse的pydev插件。
3)单元测试
TDD,测试驱动开发,Test-Driven Development.
测试用例
- senrsl@senrsl-T540p:~/test/python3$ mkdir unittest
- senrsl@senrsl-T540p:~/test/python3$ touch unittest/testDict.py
- senrsl@senrsl-T540p:~/test/python3$ touch unittest/TestDict.py
- senrsl@senrsl-T540p:~/test/python3$ vi unittest/testDict.py
- senrsl@senrsl-T540p:~/test/python3$ vi unittest/TestDict.py
- senrsl@senrsl-T540p:~/test/python3$ python3 unittest/TestDict.py
- 这个是up
- 这个是Down
- .这个是up
- 这个是Down
- .这个是up
- 这个是Down
- .这个是up
- 这个是Down
- .这个是up
- 这个是Down
- .
- ----------------------------------------------------------------------
- Ran 5 tests in 0.001s
- OK
- senrsl@senrsl-T540p:~/test/python3$
- senrsl@senrsl-T540p:~/test/python3$ cd unittest/
- senrsl@senrsl-T540p:~/test/python3/unittest$ python3 -m unittest TestDict
- 这个是up
- 这个是Down
- .这个是up
- 这个是Down
- .这个是up
- 这个是Down
- .这个是up
- 这个是Down
- .这个是up
- 这个是Down
- .
- ----------------------------------------------------------------------
- Ran 5 tests in 0.001s
- OK
- senrsl@senrsl-T540p:~/test/python3/unittest$
- senrsl@senrsl-T540p:~/test/python3/unittest$ cat testDict.py
- class testDict(dict):
- def __init__(self,**kw):
- super().__init__(**kw);
- def __getattr__(self,key):
- try:
- return self[key];
- except KeyError:
- raise AttributeError(r"'testDict'对象没属性 %s !" % key);
- def __setattr__(self,key,value):
- self[key] = value;
- senrsl@senrsl-T540p:~/test/python3/unittest$ cat TestDict.py
- #!/usr/bin/env python3
- # -*- coding:utf-8 -*-
- import unittest;
- from testDict import testDict;
- class TestDict(unittest.TestCase):
- def test_init(self):
- d = testDict(a=1,b="测试");
- self.assertEqual(d.a,1);
- self.assertEqual(d.b,"测试");
- self.assertTrue(isinstance(d,dict));
- def test_key(self):
- d = testDict();
- d["key"] = "value";
- self.assertEqual(d.key,"value");
- def test_attr(self):
- d = testDict();
- d.key = "value";
- self.assertTrue("key" in d);
- self.assertEqual(d["key"],"value");
- def test_keyerror(self):
- d = testDict();
- with self.assertRaises(KeyError):
- value = d["empty"];
- def test_attrerror(self):
- d = testDict();
- with self.assertRaises(AttributeError):
- value = d.empty;
- def setUp(self):
- print("这个是up");
- def tearDown(self):
- print("这个是Down");
- if __name__ == "__main__":
- unittest.main();
- senrsl@senrsl-T540p:~/test/python3/unittest$
4)文档测试
文档注释
python,一个靠不停space就能高潮的语言
- senrsl@senrsl-T540p:~/test/python3/unittest$ cd ..
- senrsl@senrsl-T540p:~/test/python3$ mkdir doctest
- senrsl@senrsl-T540p:~/test/python3$ cp unittest/testDict.py doctest/
- senrsl@senrsl-T540p:~/test/python3$ vi doctest/testDict.py
- senrsl@senrsl-T540p:~/test/python3$ python3 doctest/testDict.py
- senrsl@senrsl-T540p:~/test/python3$ cat doctest/testDict.py
- class testDict(dict):
- '''
- 这是一个简单的文档注释
- >>> d1 = testDict();
- >>> d1["x"] = 100;
- >>> d1.x
- 100
- >>> d1.y = 200;
- >>> d1["y"]
- 200
- >>> d2 = testDict(a=1,b=2,c="fuck");
- >>> d2.c
- 'fuck'
- >>> d2['empty']
- Traceback (most recent call last):
- ...
- KeyError: 'empty'
- >>> d2.empty
- Traceback (most recent call last):
- ...
- AttributeError: 'testDict'对象没属性 empty !
- '''
- def __init__(self,**kw):
- super().__init__(**kw);
- def __getattr__(self,key):
- try:
- return self[key];
- except KeyError:
- raise AttributeError(r"'testDict'对象没属性 %s !" % key);
- def __setattr__(self,key,value):
- self[key] = value;
- if __name__ == "__main__":
- import doctest;
- doctest.testmod();
- senrsl@senrsl-T540p:~/test/python3$
2016年06月28日17:15:39
基础姿势到这就差不多了,后面搞实际的。。。。
感觉也就两天,原来已经两周了,这主要归功于最近没好好上班,即便上班也处于长时间脱岗状态。。。。
按照规划来看,这个教程三篇就能结束了,第一篇所有基础知识,第二篇基础进阶,比方说IO,线程,通讯之类,第三片实战模拟。
反正上班也没事干,不知道在离职前能不能把python学完。。。。想想当年C primer plus学到不到一半就放下结果现在很难拿起来,太可惜了,又要重新去学那个。。。。
就这样吧。
--
senRsl
2016年06月14日11:13:17
2016年06月14日11:13:17
没有评论 :
发表评论