模块和包

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import yitian as yt # pycharm报错, 导入模块的时候. 我们看到的: 把模块中的代码执行了一遍
# 模块的搜索路径. sys.path
# import sys
# print(sys.path)
# import yitian # 如果已经导入过该模块. 此时不会再执行模块中的代码了
 
# 导入模块的时候:
# 1. 去判断当前正在导入的模块是否已经倒入过
# 2. 如果已经导入过,不会重新导入该模块
# 3. 如果没有导入过. 首先开辟一个内存空间
# 4. 把该模块中的代码放在新开辟的空间中. 运行该模块中的代码
# 5. 把该文件的名字作为当前名称空间的名字(前提是没有as)
 
# print(yt.main_person_man)
# print(main_person_man) # 当前名称空间中没有main_person_man
 
# yt.fight_on_light_top()
# yt.fight_on_shaolin()
# yt.end()
 
 
# yt.main_person_man = "宝宝" # 从另一个模块中想改变模块中变量的值
# yt.fight_on_light_top()
 
 
# def gai():
#     global main_person_man # global 当前模块的全局
#     main_person_man = "龙霸天"
#     yt.fight_on_light_top()
#
# gai()
# yt.fight_on_light_top()
 
# yt.gai()
# yt.end()
#
# print(yt.main_person_man)
 
# import yitian as yt, shediao as sd, time, os, sys,json, re
#
# sd.huashanlunjian()
# yt.fight_on_shaolin()
 
# 顺序:
# 1. 先导入内置模块
# 2. 第三方模块
# 3. 你自己定义的模块
 
 
# 此时导入的只有一个功能
# from yitian import fight_on_shaolin
# from shediao import fight_on_shaolin
 
# main_person_man = "火工头陀"
# fight_on_shaolin()
 
# def fight_on_shaolin():
#     print("我要干少林")
 
# fight_on_shaolin()
 
# from shediao import *  # 也可以导入一大堆名字. 不推荐
 
import shediao

  

posted on   =.===  阅读(105)  评论(0编辑  收藏  举报

努力加载评论中...

导航

点击右上角即可分享
微信分享提示