#sys模块

1
2
3
4
5
6
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import sys
print sys.argv[0]

sys.argv[0]输出文件本身路径
所带参数从 sys.argv[1]开始

#字符串

最左:0 1 2 3 … s[0:]
最右:… -3 -2 -1 s[:-1]
开始截取时,包含了下边界,而截取到最大范围不包括上边界
`print s
2` 输出字符串俩次

#字典映射替代switch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
def zero():
return "zero"
def one():
return "one"
def two():
return "two"
def num2Str(arg):
switcher={
0:zero,
1:one,
2:two,
3:lambda:"three"
}
func=switcher.get(arg,lambda:"nothing")
return func()
if __name__ == '__main__':
print num2Str(0)