首页 > 编程语言 > 详细

python import

时间:2014-09-10 09:33:00      阅读:290      评论:0      收藏:0      [点我收藏+]

b import 了 a, c import 了 b,c 中也会有定义

test.py

 1 __all__ = [a, b]
 2 
 3 def a():
 4     print "a"
 5 
 6 def b():
 7     print "b"
 8 
 9 def c():
10     print "c"

test_2.py

1 from test import *
2 
3 def a_2():
4     print "a_2",
5     a()

test_3.py

1 from test_2 import *
2 
3 a()
4 a_2()

运行 test_3.py

# a

# a_2 a

__all__ 的用法

test.py

 1 __all__ = [a, b]
 2 
 3 def a():
 4     print "a"
 5 
 6 def b():
 7     print "b"
 8 
 9 def c():
10     print "c"

test_2.py

1 from test import *
2 
3 a()
4 # c() cause error

 

python import

原文:http://www.cnblogs.com/mess4u/p/3963761.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!