-
Notifications
You must be signed in to change notification settings - Fork 0
/
t12.py
43 lines (33 loc) · 848 Bytes
/
t12.py
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
'''
' a test module '
__author__ = 'Nieyuan'
import sys
def test():
args = sys.argv
if len(args) == 1:
print('Hello!world')
elif len(args) == 2:
print('Hello!%s' % args[1])
else:
print("Too many arguments")
if __name__ == '__main__':
test()
'''
#当我们在命令行运行hello模块文件时,
#Python解释器把一个特殊变量__name__置为__main__
#而如果在其他地方导入该hello模块时,if判断将失败
#因此,这种if测试可以让一个模块通过命令行运行时执行一些额外的代码
#最常见的就是运行测试
#import t12
' private '
__author__ = 'Nieyuan'
def _private_1(name):
return 'Hello, %s' % name
def _private_2(name):
return 'Hi,%s' % name
def greeting(name):
if len(name) > 3:
return _private_1(name)
else:
return _private_2(name)
greeting('Pengting')