首页 > 代码库 > python import

python import

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