[Python] multiple import

[code lang=”python”]#a.py
print("in a.py berfore import b")
import b
print("in a.py after import b")
[/code]
[code lang=”python”]#b.py
print ("in b.py")
[/code]
[code lang=”python”]#c.py
print("in c.py berfore import b")
import b
print("in c.py after import b")
[/code]
[code lang=”python”]#d.py
print("in d.py berfore import a")
import a
print("in d.py after import a")

print("in d.py berfore import c")
import c
print("in d.py after import c")
[/code]

in d.py berfore import a
in a.py berfore import b
in b.py
in a.py after import b
in d.py after import a
in d.py berfore import c
in c.py berfore import b
in c.py after import b
in d.py after import c
>>> a.b.x = 1
>>> c.b.x
1
>>> a.b

>>> c.b

>>> 

重複import會被視為同一個物件

發佈留言

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料