Package

  • ๅผ•็”จๆŸไธชpythonๆ–‡ไปถ๏ผŒไผšๅˆๅง‹ๅŒ–่ฏฅๆ–‡ไปถ็š„ๅ…จๅฑ€ๅ˜้‡๏ผŒ่€Œไธ”ๅช่ขซๅˆๅง‹ๅŒ–ไธ€ๆฌก

bovenson@Dell:~/Git/notes/Python/Code/LearnPythonCode/pyl$ tree
.
โ”œโ”€โ”€ 002.py
โ”œโ”€โ”€ a001.py
โ”œโ”€โ”€ a002.py
โ”œโ”€โ”€ __init__.py
โ””โ”€โ”€ __pycache__
    โ”œโ”€โ”€ a001.cpython-36.pyc
    โ””โ”€โ”€ a002.cpython-36.pyc

1 directory, 6 files
bovenson@Dell:~/Git/notes/Python/Code/LearnPythonCode/pyl$ cat a001.py 
#!/bin/python3

class A:
    def __init__(self):
        print("init class A")

g = [A()]

def fg():
    # global gb     # NameError: name 'gb' is not defined
    # print(gb)
    g.append(0)
    print("run fg, and g: ", g)
bovenson@Dell:~/Git/notes/Python/Code/LearnPythonCode/pyl$ cat a002.py 
#!/bin/python3

from a001 import fg, g

def cfg():
    g.append("in a001")
    fg()
bovenson@Dell:~/Git/notes/Python/Code/LearnPythonCode/pyl$ cat 002.py 
#!/bin/python3 

from a001 import fg, g
from a002 import cfg

gb = []

g.append('in 002')
fg()
g.append('in 002')
cfg()
g.append('over')
print(g)
bovenson@Dell:~/Git/notes/Python/Code/LearnPythonCode/pyl$ python3 002.py 
init class A
run fg, and g:  [<a001.A object at 0x7f6bf74f3d30>, 'in 002', 0]
run fg, and g:  [<a001.A object at 0x7f6bf74f3d30>, 'in 002', 0, 'in 002', 'in a001', 0]
[<a001.A object at 0x7f6bf74f3d30>, 'in 002', 0, 'in 002', 'in a001', 0, 'over']

ๆœ€ๅŽๆ›ดๆ–ฐไบŽ