-
Notifications
You must be signed in to change notification settings - Fork 0
/
pythonadv_OOP_5.html
1506 lines (1349 loc) · 121 KB
/
pythonadv_OOP_5.html
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>Python进阶(五)模块和包 | BEIDAO.</title><meta name="keywords" content="面向对象编程,Python进阶"><meta name="author" content="Beidaos"><meta name="copyright" content="Beidaos"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#C6B3B1"><meta name="mobile-web-app-capable" content="yes"><meta name="apple-touch-fullscreen" content="yes"><meta name="apple-mobile-web-app-title" content="Python进阶(五)模块和包"><meta name="application-name" content="Python进阶(五)模块和包"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="default"><link rel="bookmark" href="/img/siteicon/apple-touch-icon.png"><link rel="apple-touch-icon-precomposed" sizes="180x180" href="/img/siteicon/apple-touch-icon.png"><link rel="apple-touch-icon" sizes="192x192" href="/img/siteicon/apple-touch-icon.png"><link rel="apple-touch-icon" sizes="512x512" href="/img/siteicon/apple-touch-icon.png"><link rel="apple-touch-startup-image" media="screen and (device-width:320px) and (device-height:568px) and (-webkit-device-pixel-ratio:2) and (orientation:landscape)" href="/img/siteicon/splashIcons/icon_1136x640.png"><link rel="apple-touch-startup-image" media="screen and (device-width:320px) and (device-height:568px) and (-webkit-device-pixel-ratio:2) and (orientation:portrait)" href="/img/siteicon/splashIcons/icon_640x1136.png"><link rel="apple-touch-startup-image" media="screen and (device-width:414px) and (device-height:896px) and (-webkit-device-pixel-ratio:3) and (orientation:landscape)" href="/img/siteicon/splashIcons/icon_2688x1242.png"><link rel="apple-touch-startup-image" media="screen and (device-width:414px) and (device-height:896px) and (-webkit-device-pixel-ratio:2) and (orientation:landscape)" href="/img/siteicon/splashIcons/icon_1792x828.png"><link rel="apple-touch-startup-image" media="screen and (device-width:375px) and (device-height:812px) and (-webkit-device-pixel-ratio:3) and (orientation:portrait)" href="/img/siteicon/splashIcons/icon_1125x2436.png"><link rel="apple-touch-startup-image" media="screen and (device-width:414px) and (device-height:896px) and (-webkit-device-pixel-ratio:2) and (orientation:portrait)" href="/img/siteicon/splashIcons/icon_828x1792.png"><link rel="apple-touch-startup-image" media="screen and (device-width:375px) and (device-height:812px) and (-webkit-device-pixel-ratio:3) and (orientation:landscape)" href="/img/siteicon/splashIcons/icon_2436x1125.png"><link rel="apple-touch-startup-image" media="screen and (device-width:414px) and (device-height:736px) and (-webkit-device-pixel-ratio:3) and (orientation:portrait)" href="/img/siteicon/splashIcons/icon_1242x2208.png"><link rel="apple-touch-startup-image" media="screen and (device-width:414px) and (device-height:736px) and (-webkit-device-pixel-ratio:3) and (orientation:landscape)" href="/img/siteicon/splashIcons/icon_2208x1242.png"><link rel="apple-touch-startup-image" media="screen and (device-width:375px) and (device-height:667px) and (-webkit-device-pixel-ratio:2) and (orientation:landscape)" href="/img/siteicon/splashIcons/icon_1334x750.png"><link rel="apple-touch-startup-image" media="screen and (device-width:375px) and (device-height:667px) and (-webkit-device-pixel-ratio:2) and (orientation:portrait)" href="/img/siteicon/splashIcons/icon_750x1334.png"><link rel="apple-touch-startup-image" media="screen and (device-width:1024px) and (device-height:1366px) and (-webkit-device-pixel-ratio:2) and (orientation:landscape)" href="/img/siteicon/splashIcons/icon_2732x2048.png"><meta name="description" content="目标 了解模块 导入模块 制作模块 __all__ 包的使用方法 一. 模块 Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句。 模块能定义函数,类和变量,模块里也能包含可执行的代码。 1.1. 导入模块 1.1.1 导入模块的方式 import 模块名 from 模块名 import 功能名 fro">
<meta property="og:type" content="article">
<meta property="og:title" content="Python进阶(五)模块和包">
<meta property="og:url" content="https://www.beidaoaz.top/pythonadv_OOP_5.html">
<meta property="og:site_name" content="BEIDAO.">
<meta property="og:description" content="目标 了解模块 导入模块 制作模块 __all__ 包的使用方法 一. 模块 Python 模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句。 模块能定义函数,类和变量,模块里也能包含可执行的代码。 1.1. 导入模块 1.1.1 导入模块的方式 import 模块名 from 模块名 import 功能名 fro">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/%E5%8D%9A%E5%AE%A2%E7%AB%99%E7%82%B9%E9%85%8D%E5%9B%BE/python-logo.6puefdh4wtk0.png">
<meta property="article:published_time" content="2023-07-09T00:00:00.000Z">
<meta property="article:modified_time" content="2024-03-01T07:01:44.698Z">
<meta property="article:author" content="Beidaos">
<meta property="article:tag" content="面向对象编程">
<meta property="article:tag" content="Python进阶">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/%E5%8D%9A%E5%AE%A2%E7%AB%99%E7%82%B9%E9%85%8D%E5%9B%BE/python-logo.6puefdh4wtk0.png"><link rel="shortcut icon" href="/private_img/web_logo.png"><link rel="canonical" href="https://www.beidaoaz.top/pythonadv_OOP_5"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//npm.elemecdn.com"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><meta name="google-site-verification" content="xxx"/><meta name="baidu-site-verification" content="code-xxx"/><meta name="msvalidate.01" content="xxx"/><link rel="manifest" href="/manifest.json"/><meta name="msapplication-TileColor" content="var(--anzhiyu-main)"/><link rel="apple-touch-icon" sizes="180x180" href="/img/siteicon/128.png"/><link rel="icon" type="image/png" sizes="32x32" href="/img/siteicon/32.png"/><link rel="icon" type="image/png" sizes="16x16" href="/img/siteicon/16.png"/><link rel="mask-icon" href="/img/siteicon/128.png" color="#5bbad5"/><script>if ('serviceWorker' in navigator) {
if (navigator.serviceWorker.controller) {
navigator.serviceWorker.addEventListener('controllerchange', function() {
location.reload()
})
}
window.addEventListener('load', function() {
navigator.serviceWorker.register('/service-worker.js')
})
}</script><link rel="stylesheet" href="css/index.css"><link rel="stylesheet" href="https://npm.elemecdn.com/[email protected]/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://npm.elemecdn.com/@fancyapps/[email protected]/dist/fancybox.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
root: '/',
friends_vue_info: undefined,
navMusic: true,
algolia: undefined,
localSearch: {"path":"/search.xml","preload":true,"languages":{"hits_empty":"找不到您查询的内容:${query}"}},
translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"简","rightMenuMsgToTraditionalChinese":"转为繁体","rightMenuMsgToSimplifiedChinese":"转为简体"},
noticeOutdate: {"limitDay":30,"position":"top","messagePrev":"本文上次更新距离今天已经过去","messageNext":"天, 文中内容可能已经过时,望周知。"},
highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":330},
copy: {
success: '复制成功',
error: '复制错误',
noSupport: '浏览器不支持'
},
relativeDate: {
homepage: false,
post: false
},
runtime: '天',
date_suffix: {
just: '刚刚',
min: '分钟前',
hour: '小时前',
day: '天前',
month: '个月前'
},
copyright: undefined,
lightbox: 'fancybox',
Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#3b70fc","bgDark":"#1f1f1f","position":"top-center"},
source: {
justifiedGallery: {
js: 'https://npm.elemecdn.com/[email protected]/dist/fjGallery.min.js',
css: 'https://npm.elemecdn.com/[email protected]/dist/fjGallery.css'
}
},
isPhotoFigcaption: false,
islazyload: true,
isAnchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
title: 'Python进阶(五)模块和包',
isPost: true,
isHome: false,
isHighlightShrink: false,
isToc: true,
postUpdate: '2024-03-01 15:01:44'
}</script><noscript><style type="text/css">
#nav {
opacity: 1
}
.justified-gallery img {
opacity: 1
}
#recent-posts time,
#post-meta time {
display: inline !important
}
</style></noscript><script>(win=>{
win.saveToLocal = {
set: function setWithExpiry(key, value, ttl) {
if (ttl === 0) return
const now = new Date()
const expiryDay = ttl * 86400000
const item = {
value: value,
expiry: now.getTime() + expiryDay,
}
localStorage.setItem(key, JSON.stringify(item))
},
get: function getWithExpiry(key) {
const itemStr = localStorage.getItem(key)
if (!itemStr) {
return undefined
}
const item = JSON.parse(itemStr)
const now = new Date()
if (now.getTime() > item.expiry) {
localStorage.removeItem(key)
return undefined
}
return item.value
}
}
win.getScript = url => new Promise((resolve, reject) => {
const script = document.createElement('script')
script.src = url
script.async = true
script.onerror = reject
script.onload = script.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
script.onload = script.onreadystatechange = null
resolve()
}
document.head.appendChild(script)
})
win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
const link = document.createElement('link')
link.rel = 'stylesheet'
link.href = url
if (id) link.id = id
link.onerror = reject
link.onload = link.onreadystatechange = function() {
const loadState = this.readyState
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
link.onload = link.onreadystatechange = null
resolve()
}
document.head.appendChild(link)
})
win.activateDarkMode = function () {
document.documentElement.setAttribute('data-theme', 'dark')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#18171d')
}
}
win.activateLightMode = function () {
document.documentElement.setAttribute('data-theme', 'light')
if (document.querySelector('meta[name="theme-color"]') !== null) {
document.querySelector('meta[name="theme-color"]').setAttribute('content', '#C6B3B1')
}
}
const t = saveToLocal.get('theme')
const now = new Date()
const hour = now.getHours()
const isNight = hour <= 8 || hour >= 22
if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
else if (t === 'light') activateLightMode()
else activateDarkMode()
const asideStatus = saveToLocal.get('aside-status')
if (asideStatus !== undefined) {
if (asideStatus === 'hide') {
document.documentElement.classList.add('hide-aside')
} else {
document.documentElement.classList.remove('hide-aside')
}
}
const detectApple = () => {
if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
document.documentElement.classList.add('apple')
}
}
detectApple()
})(window)</script><link rel="preconnect" href="https://fonts.googleapis.com"><link rel="preconnect" href="https://fonts.gstatic.com" crossorigin><link href="https://fonts.loli.net/css2?family=Noto+Serif+SC:wght@400;500;700&display=swap" rel="stylesheet"><link href="https://fonts.loli.net/css2?family=Ma+Shan+Zheng:wght@400;500;700&display=swap" rel="stylesheet"><link rel="stylesheet" href="/css/custom.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/background-page.css?1"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zhheo/JS-Heo@main/tag-link/tag-link.css"><!-- hexo injector head_end start -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/katex.min.css">
<link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-clock-anzhiyu/lib/clock.min.css" /><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/assets/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/tag_plugins.css" media="defer" onload="this.media='all'"><script src="https://cdn.cbd.int/hexo-butterfly-tag-plugins-plus@latest/lib/assets/carousel-touch.js"></script><!-- hexo injector head_end end --><meta name="generator" content="Hexo 6.3.0"></head><body data-type="anzhiyu"><div id="web_bg"></div><div id="an_music_bg"></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog_name"><div class="back-home-button" tabindex="-1"><i class="anzhiyufont anzhiyu-icon-grip-vertical"></i><div class="back-menu-list-groups"><div class="back-menu-list-group"><div class="back-menu-list-title">学术</div><div class="back-menu-list"><a class="back-menu-item" href="https://sci-hub.st/" rel="external nofollow noreferrer" title="Sci-hub" target="_blank"><img class="back-menu-item-icon" src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/图标/ravenround_hs.f9qogiemdnk.gif" alt="Sci-hub"/><span class="back-menu-item-text">Sci-hub</span></a><a class="back-menu-item" href="https://www.connectedpapers.com/" rel="external nofollow noreferrer" title="ConnetPapers" target="_blank"><img class="back-menu-item-icon" src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/图标/Connected Papers.avesmhofaig.jpg" alt="ConnetPapers"/><span class="back-menu-item-text">ConnetPapers</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">工具</div><div class="back-menu-list"><a class="back-menu-item" href="https://vercel.com/" rel="external nofollow noreferrer" title="Vercel" target="_blank"><img class="back-menu-item-icon" src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/图标/vercel.7910zc14sj40.png" alt="Vercel"/><span class="back-menu-item-text">Vercel</span></a><a class="back-menu-item" href="https://picx.xpoet.cn/" rel="external nofollow noreferrer" title="PicX" target="_blank"><img class="back-menu-item-icon" src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/图标/PicX.1erb7rkva5c0.ico" alt="PicX"/><span class="back-menu-item-text">PicX</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">网页</div><div class="back-menu-list"><a class="back-menu-item" href="https://www.bilibili.com/" rel="external nofollow noreferrer" title="BiliBili" target="_blank"><img class="back-menu-item-icon" src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/图标/bilibili.7fu3r06fhp80.svg" alt="BiliBili"/><span class="back-menu-item-text">BiliBili</span></a></div></div><div class="back-menu-list-group"><div class="back-menu-list-title">镜像站</div><div class="back-menu-list"><a class="back-menu-item" href="https://mirrors.tuna.tsinghua.edu.cn/" rel="external nofollow noreferrer" title="清华镜像站" target="_blank"><img class="back-menu-item-icon" src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/图标/logo-small.4bmf6842eso0.png" alt="清华镜像站"/><span class="back-menu-item-text">清华镜像站</span></a><a class="back-menu-item" href="https://developer.aliyun.com/mirror/?spm=a2c6h.25603864.0.0.7cff28b9BKDFoW" rel="external nofollow noreferrer" title="阿里云镜像站" target="_blank"><img class="back-menu-item-icon" src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/图标/阿里云.3j8goscmtmu0.svg" alt="阿里云镜像站"/><span class="back-menu-item-text">阿里云镜像站</span></a></div></div></div></div><a id="site-name" href="/index.html"><div class="title">BEIDAO.</div><i class="anzhiyufont anzhiyu-icon-house-chimney"></i></a></span><div class="mask-name-container"><center id="name-container"><a id="page-name" href="javascript:anzhiyu.scrollToDest(0, 500)" rel="external nofollow noreferrer">PAGE_NAME</a></center></div><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><span> 文章</span></a><ul class="menus_item_child" style="left:-79px;"><li><a class="site-page child faa-parent animated-hover" href="/archives/"><i class="anzhiyufont anzhiyu-icon-box-archive faa-tada" style="font-size: 0.9em;"></i><span> 归档</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/categories/"><i class="anzhiyufont anzhiyu-icon-shapes faa-tada" style="font-size: 0.9em;"></i><span> 分类</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/tags/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-biaoqiantags3"></use></svg><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><span> 社交</span></a><ul class="menus_item_child" style="left:-31px;"><li><a class="site-page child faa-parent animated-hover" href="/link/"><i class="anzhiyufont anzhiyu-icon-link faa-tada" style="font-size: 0.9em;"></i><span> 友链</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/essay/"><i class="anzhiyufont anzhiyu-icon-lightbulb faa-tada" style="font-size: 0.9em;"></i><span> 闲言碎语</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><span> 我的</span></a><ul class="menus_item_child" style="left:-79px;"><li><a class="site-page child faa-parent animated-hover" href="/music/?id=886726002&server=netease"><i class="anzhiyufont anzhiyu-icon-music faa-tada" style="font-size: 0.9em;"></i><span> 音乐馆</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/collect/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-dropboxdropbox4"></use></svg><span> 藏宝阁</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/album/"><i class="anzhiyufont anzhiyu-icon-images faa-tada" style="font-size: 0.9em;"></i><span> 相册集</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><span> 关于</span></a><ul class="menus_item_child" style="left:17px;"><li><a class="site-page child faa-parent animated-hover" href="/about/"><i class="anzhiyufont anzhiyu-icon-paper-plane faa-tada" style="font-size: 0.9em;"></i><span> 关于博主</span></a></li></ul></div></div></div><div id="nav-right"><div class="nav-button" id="randomPost_button"><a class="site-page" onclick="toRandomPost()" title="随机前往一个文章" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="anzhiyufont anzhiyu-icon-dice"></i></a></div><div class="nav-button" id="search-button"><a class="site-page social-icon search" href="javascript:void(0);" rel="external nofollow noreferrer" title="搜索内容 - 搜一搜,省时又省力"><i class="anzhiyufont anzhiyu-icon-magnifying-glass"></i><span> 搜索</span></a></div><div class="nav-button" id="changeBg-button"><a class="site-page social-icon search" href="javascript:void(0);" rel="external nofollow noreferrer" onclick="toggleWinbox()" title="切换背景 - 换一个背景,换一种感觉"><i class="iconfont icon-qiehuankapian"></i></a></div><div class="nav-button" id="darkmode_navswitch"><a class="darkmode_switchbutton" type="button" href="javascript:void(0);" rel="external nofollow noreferrer" title="浅色和深色模式转换" onclick="rm.switchDarkMode()"><i class="anzhiyufont anzhiyu-icon-circle-half-stroke" style="font-size: 1.3rem"></i></a></div><div class="nav-button" id="nav-totop"><a class="totopbtn" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="anzhiyufont anzhiyu-icon-arrow-up"></i><span id="percent" onclick="anzhiyu.scrollToDest(0,500)">0</span></a></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="anzhiyufont anzhiyu-icon-bars"></i></a></div></div></nav><div id="post-info"><div id="post-firstinfo"><div class="meta-firstline"><a class="post-meta-original">原创</a><span class="post-meta-categories"><span class="post-meta-separator"></span><i class="anzhiyufont anzhiyu-icon-inbox post-meta-icon"></i><a class="post-meta-categories" href="categories/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/">面向对象编程</a></span><span class="article-meta tags"><a class="article-meta__tags" href="tags/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/"><span><i class="iconfont icon-Tags"></i>面向对象编程</span></a><a class="article-meta__tags" href="tags/Python%E8%BF%9B%E9%98%B6/"><span><i class="iconfont icon-Tags"></i>Python进阶</span></a></span></div></div><h1 class="post-title">Python进阶(五)模块和包</h1><div id="post-meta"><div class="meta-firstline"><i class="iconfont icon-zuozhe"></i><span class="post-meta-author">安志</span><span class="post-meta-date"><span class="post-meta-separator"></span><i class="anzhiyufont anzhiyu-icon-calendar-days post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-07-09T00:00:00.000Z" title="发表于 2023-07-09 08:00:00">2023-07-09</time><span class="post-meta-separator"></span><i class="anzhiyufont anzhiyu-icon-history post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2024-03-01T07:01:44.698Z" title="更新于 2024-03-01 15:01:44">2024-03-01</time></span></div><div class="meta-secondline"><span class="post-meta-separator"></span><span class="post-meta-wordcount"><i class="anzhiyufont anzhiyu-icon-file-word post-meta-icon" title="文章字数"></i><span class="post-meta-label" title="文章字数">字数总计:</span><span class="word-count" title="文章字数">1.7k</span><span class="post-meta-separator"></span><i class="anzhiyufont anzhiyu-icon-clock post-meta-icon" title="阅读时长"></i><span class="post-meta-label" title="阅读时长">阅读时长:</span><span>5分钟</span></span><span class="post-meta-separator"></span><span class="post-meta-position" title="作者IP属地为北京"><i class="anzhiyufont anzhiyu-icon-location-dot"></i>北京</span></div></div></div><section class="main-hero-waves-area waves-area"><svg class="waves-svg" xmlns="http://www.w3.org/2000/svg" xlink="http://www.w3.org/1999/xlink" viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto"><defs><path id="gentle-wave" d="M -160 44 c 30 0 58 -18 88 -18 s 58 18 88 18 s 58 -18 88 -18 s 58 18 88 18 v 44 h -352 Z"></path></defs><g class="parallax"><use href="#gentle-wave" x="48" y="0"></use><use href="#gentle-wave" x="48" y="3"></use><use href="#gentle-wave" x="48" y="5"></use><use href="#gentle-wave" x="48" y="7"></use></g></svg></section><div id="post-top-cover"><img class="nolazyload" id="post-top-bg" src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png"></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="目标">目标</h1>
<ul class="lvl-0">
<li class="lvl-2">了解模块</li>
<li class="lvl-2">导入模块</li>
<li class="lvl-2">制作模块</li>
<li class="lvl-2"><code>__all__</code></li>
<li class="lvl-2">包的使用方法</li>
</ul>
<h1 id="一-模块">一. 模块</h1>
<p>Python <strong>模块(Module),是一个 Python 文件,以 .py 结尾,包含了 Python 对象定义和Python语句。</strong></p>
<p><font color='red'>模块能定义函数,类和变量</font>,模块里也<font color='red'>能包含可执行的代码</font>。</p>
<h2 id="1-1-导入模块">1.1. 导入模块</h2>
<h3 id="1-1-1-导入模块的方式">1.1.1 导入模块的方式</h3>
<ul class="lvl-0">
<li class="lvl-2">
<p>import 模块名</p>
</li>
<li class="lvl-2">
<p>from 模块名 import 功能名</p>
</li>
<li class="lvl-2">
<p>from 模块名 import *</p>
</li>
<li class="lvl-2">
<p>import 模块名 as 别名</p>
</li>
<li class="lvl-2">
<p>from 模块名 import 功能名 as 别名</p>
</li>
</ul>
<h3 id="1-1-2-导入方式详解">1.1.2 导入方式详解</h3>
<h4 id="1-1-2-1-import">1.1.2.1 import</h4>
<ul class="lvl-0">
<li class="lvl-2">
<p><font color='red'>语法</font></p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 1. 导入模块</span></span><br><span class="line"><span class="keyword">import</span> 模块名</span><br><span class="line"><span class="keyword">import</span> 模块名<span class="number">1</span>, 模块名<span class="number">2.</span>..</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2. 调用功能</span></span><br><span class="line">模块名.功能名()</span><br></pre></td></tr></table></figure>
<ul class="lvl-0">
<li class="lvl-2">
<p>示例</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> math</span><br><span class="line"><span class="built_in">print</span>(math.sqrt(<span class="number">9</span>)) <span class="comment"># 3.0</span></span><br></pre></td></tr></table></figure>
<h4 id="1-1-2-2-from…import…">1.1.2.2 from…import…</h4>
<ul class="lvl-0">
<li class="lvl-2">
<p>语法</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 1. 导入模块及其功能名 </span></span><br><span class="line"><span class="keyword">from</span> 模块名 <span class="keyword">import</span> 功能<span class="number">1</span>, 功能<span class="number">2</span>, 功能<span class="number">3.</span>..</span><br><span class="line"><span class="comment"># 2. 调用功能,不需要书写模块名</span></span><br><span class="line">功能名()</span><br></pre></td></tr></table></figure>
<ul class="lvl-0">
<li class="lvl-2">
<p>示例</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">from</span> math <span class="keyword">import</span> sqrt</span><br><span class="line"><span class="built_in">print</span>(sqrt(<span class="number">9</span>))</span><br></pre></td></tr></table></figure>
<h4 id="1-1-2-3-from-…-import-———导入模块所有代码(含功能函数)">1.1.2.3 from … import * ———导入模块所有代码(含功能函数)</h4>
<ul class="lvl-0">
<li class="lvl-2">
<p>语法</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 1. 导入模块及所有功能 *</span></span><br><span class="line"><span class="keyword">from</span> 模块名 <span class="keyword">import</span> *</span><br><span class="line"><span class="comment"># 2. 调用功能,不需要书写模块名</span></span><br><span class="line">功能名()</span><br></pre></td></tr></table></figure>
<ul class="lvl-0">
<li class="lvl-2">
<p>示例</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">from</span> math <span class="keyword">import</span> *</span><br><span class="line"><span class="built_in">print</span>(sqrt(<span class="number">9</span>))</span><br></pre></td></tr></table></figure>
<h4 id="1-1-2-4-as定义别名">1.1.2.4 as定义别名</h4>
<ul class="lvl-0">
<li class="lvl-2">
<p>语法</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 模块定义别名(调用时模块只能使用别名)</span></span><br><span class="line"><span class="keyword">import</span> 模块名 <span class="keyword">as</span> 别名</span><br><span class="line"></span><br><span class="line"><span class="comment"># 功能定义别名(调用时功能只能使用别名)</span></span><br><span class="line"><span class="keyword">from</span> 模块名 <span class="keyword">import</span> 功能 <span class="keyword">as</span> 别名</span><br></pre></td></tr></table></figure>
<ul class="lvl-0">
<li class="lvl-2">
<p>示例</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 模块别名---只能使用模块别名来调用功能</span></span><br><span class="line"><span class="keyword">import</span> time <span class="keyword">as</span> tt</span><br><span class="line"></span><br><span class="line">tt.sleep(<span class="number">2</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'hello'</span>)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 功能别名---只能使用功能别名来调用 </span></span><br><span class="line"><span class="keyword">from</span> time <span class="keyword">import</span> sleep <span class="keyword">as</span> sl</span><br><span class="line">sl(<span class="number">2</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="string">'hello'</span>)</span><br></pre></td></tr></table></figure>
<h2 id="1-2-制作模块">1.2. 制作模块</h2>
<p>在Python中,每个Python文件都可以作为一个模块,模块的名字就是文件的名字。<strong>也就是说自定义模块名必须要符合标识符命名规则。</strong></p>
<p>模块的作用:提升效率,降低工作量。</p>
<h3 id="1-2-1-定义模块">1.2.1 定义模块</h3>
<p>新建一个Python文件,命名为<code>my_module1.py</code>,并定义<code>testA</code>函数。</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">testA</span>(<span class="params">a, b</span>):</span><br><span class="line"> <span class="built_in">print</span>(a + b)</span><br></pre></td></tr></table></figure>
<h3 id="1-2-2-测试模块">1.2.2 测试模块</h3>
<p>在实际开发中,当一个开发人员编写完一个模块后,为了让模块能够在项目中达到想要的效果,这个开发人员会自行在py文件中添加一些测试信息.,例如,在<code>my_module1.py</code>文件中添加测试代码。</p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">testA</span>(<span class="params">a, b</span>):</span><br><span class="line"> <span class="built_in">print</span>(a + b)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">testA(<span class="number">1</span>, <span class="number">1</span>)</span><br></pre></td></tr></table></figure>
<p>此时,无论是当前文件,还是其他已经导入了该模块的文件,在运行的时候都会自动执行<code>testA</code>函数的调用。</p>
<p><strong><font color='red'>解决办法如下:</font></strong></p>
<pre><code> `__name__`表示系统变量,是模块的标识符,值是:如果是自身模块是`__mian__`,否则是当前模块的名字
</code></pre>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">def</span> <span class="title function_">testA</span>(<span class="params">a, b</span>):</span><br><span class="line"> <span class="built_in">print</span>(a + b)</span><br><span class="line"></span><br><span class="line"><span class="comment"># __name__表示系统变量,是模块的标识符,值是:如果是自身模块是__mian__,否则是当前模块的名字</span></span><br><span class="line"><span class="keyword">if</span> __name__ == <span class="string">'__main__'</span>:</span><br><span class="line"> add_fun(<span class="number">3231</span>, <span class="number">123</span>)</span><br></pre></td></tr></table></figure>
<h3 id="1-2-3-调用模块">1.2.3 调用模块</h3>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> my_module1</span><br><span class="line">my_module1.testA(<span class="number">1</span>, <span class="number">1</span>)</span><br></pre></td></tr></table></figure>
<h3 id="1-2-4-注意事项">1.2.4 注意事项</h3>
<p>如果使用<code>from .. import ..</code>或<code>from .. import *</code>导入多个模块的时候,且模块内有同名功能。<strong><font color='red'>当调用这个同名功能的时候,调用到的是后面导入的模块的功能。</font></strong></p>
<ul class="lvl-0">
<li class="lvl-2">
<p>示例</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 模块1代码</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">my_test</span>(<span class="params">a, b</span>):</span><br><span class="line"> <span class="built_in">print</span>(a + b)</span><br><span class="line"></span><br><span class="line"><span class="comment"># 模块2代码</span></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">my_test</span>(<span class="params">a, b</span>):</span><br><span class="line"> <span class="built_in">print</span>(a - b)</span><br><span class="line"> </span><br><span class="line"><span class="comment"># 导入模块和调用功能代码</span></span><br><span class="line"><span class="keyword">from</span> my_module1 <span class="keyword">import</span> my_test</span><br><span class="line"><span class="keyword">from</span> my_module2 <span class="keyword">import</span> my_test</span><br><span class="line"></span><br><span class="line"><span class="comment"># my_test函数是模块2中的函数</span></span><br><span class="line">my_test(<span class="number">1</span>, <span class="number">1</span>)</span><br></pre></td></tr></table></figure>
<h2 id="1-3-模块定位顺序">1.3. 模块定位顺序</h2>
<p>当导入一个模块,Python解析器对模块位置的搜索顺序是:</p>
<ol>
<li class="lvl-3">
<p>当前目录</p>
</li>
<li class="lvl-3">
<p>如果不在当前目录,Python则搜索在shell变量PYTHONPATH下的每个目录。</p>
</li>
<li class="lvl-3">
<p>如果都找不到,Python会察看默认路径。UNIX下,默认路径一般为/usr/local/lib/python/</p>
</li>
</ol>
<p>模块搜索路径存储在system模块的sys.path变量中。变量里包含当前目录,PYTHONPATH和由安装过程决定的默认目录。</p>
<ul class="lvl-0">
<li class="lvl-2">
<p>注意</p>
<ul class="lvl-2">
<li class="lvl-4"><strong>自己的文件名不要和已有模块名重复</strong>,否则导致模块功能无法使用</li>
<li class="lvl-4"><strong><code>使用from 模块名 import 功能</code>的时候,如果功能名字重复,调用到的是最后定义或导入的功能。</strong></li>
</ul>
</li>
<li class="lvl-2">
<blockquote>
<pre><code class="language-python"># 1.自己的文件名不能和已有的模块名,如果重复导致模块无法使用 -- random函数为例:
# from random import randint
# num = randint(0, 100)
# print(num)
# 2.使用from 模块名 import 功能 导入模块的功能的时候,如果功能名字重复,导入的时候后定义或后导入的这个同名功能被调用
# sleep场景
# from time import sleep
# sleep(2)
def sleep():
print('自定义功能')
sleep(2)
<figure class="highlight plaintext"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br><span class="line">- 拓展:</span><br><span class="line"></span><br><span class="line">```python</span><br><span class="line"># 拓展: 名字重复</span><br><span class="line"># 问题: import 模块名 是否担心 功能名字重复的问题 -- 不需要,因为调用的时候会加模块名</span><br><span class="line">import time</span><br><span class="line">print(time)</span><br><span class="line"></span><br><span class="line">time = 1</span><br><span class="line">print(time)</span><br><span class="line"></span><br><span class="line"># 问题: 为什么变量也能覆盖模块? -- 在Python语言中,数据是通过 引用 传递的</span><br></pre></td></tr></table></figure>
</code></pre>
</blockquote>
</li>
</ul>
<h2 id="1-4-all-——在模块文件中设置">1.4. <code>__all__</code>——在模块文件中设置</h2>
<p>如果<font color='red'>一个模块文件</font>中有<code>__all__</code>变量,<font color='blue'>当使用<code>from xxx import *</code>导入时,只能导入这个列表中的元素。</font></p>
<ul class="lvl-0">
<li class="lvl-2">
<p>my_module1模块代码</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment"># 定义多个功能,把某个功能 添加到__all__</span></span><br><span class="line">__all__ = [<span class="string">'testA'</span>]</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">testA</span>():</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'这是A'</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">testB</span>():</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'这是B'</span>)</span><br></pre></td></tr></table></figure>
<ul class="lvl-0">
<li class="lvl-2">
<p>导入模块的文件代码</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">from</span> my_module1 <span class="keyword">import</span> *</span><br><span class="line">testA()</span><br><span class="line"></span><br><span class="line"><span class="comment"># 因为testBh函数没有添加到all列表,只有all列表里面的功能才能导入</span></span><br><span class="line">testB()</span><br></pre></td></tr></table></figure>
<p><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@Python/pythonStudy_img/image-20190305175727272.png" alt="image-20190305175727272"></p>
<h1 id="二-包">二. 包</h1>
<p><strong>包将有联系的模块组织在一起,即放到同一个文件夹下,并且在这个文件夹创建一个名字为<code>__init__.py</code> 文件</strong>,那么这个文件夹就称之为包。</p>
<h2 id="2-1-制作包">2.1 制作包</h2>
<p>[New] — [Python Package] — 输入包名 — [OK] — 新建功能模块(有联系的模块)。</p>
<p>注意:新建包后,包内部会自动创建<code>__init__.py</code>文件,这个文件控制着包的导入行为。</p>
<h3 id="2-1-1-示例">2.1.1 示例</h3>
<ol>
<li class="lvl-3">
<p>新建包<code>mypackage</code></p>
</li>
<li class="lvl-3">
<p>新建包内模块:<code>my_module1</code> 和 <code>my_module2</code></p>
</li>
<li class="lvl-3">
<p>模块内代码如下</p>
</li>
</ol>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment"># my_module1</span></span><br><span class="line"><span class="built_in">print</span>(<span class="number">1</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">info_print1</span>():</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'my_module1'</span>)</span><br></pre></td></tr></table></figure>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="comment"># my_module2</span></span><br><span class="line"><span class="built_in">print</span>(<span class="number">2</span>)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">def</span> <span class="title function_">info_print2</span>():</span><br><span class="line"> <span class="built_in">print</span>(<span class="string">'my_module2'</span>)</span><br></pre></td></tr></table></figure>
<h2 id="2-2-导入包">2.2 导入包</h2>
<h3 id="2-2-1-方法一">2.2.1 方法一</h3>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> 包名.模块名</span><br><span class="line"></span><br><span class="line">包名.模块名.目标</span><br></pre></td></tr></table></figure>
<h4 id="2-2-1-1-示例">2.2.1.1 示例</h4>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> my_package.my_module1</span><br><span class="line"></span><br><span class="line">my_package.my_module1.info_print1()</span><br></pre></td></tr></table></figure>
<h3 id="2-2-2-方法二">2.2.2 方法二</h3>
<p><strong>注意</strong>:<font color='red'>必须在包的<code>__init__.py</code>文件中添加<code>__all__ = []</code>,控制允许导入的模块列表。</font></p>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">from</span> 包名 <span class="keyword">import</span> *</span><br><span class="line">模块名.目标</span><br></pre></td></tr></table></figure>
<h4 id="2-2-2-1-示例">2.2.2.1 示例</h4>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">from</span> my_package <span class="keyword">import</span> *</span><br><span class="line"></span><br><span class="line">my_module1.info_print1()</span><br></pre></td></tr></table></figure>
<h1 id="三-总结">三. 总结</h1>
<ul class="lvl-0">
<li class="lvl-2">
<p>导入模块方法</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> 模块名</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> 模块名 <span class="keyword">import</span> 目标</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> 模块名 <span class="keyword">import</span> *</span><br></pre></td></tr></table></figure>
<ul class="lvl-0">
<li class="lvl-2">
<p>导入包</p>
</li>
</ul>
<figure class="highlight python"><table><tr><td class="code"><pre><span class="line"><span class="keyword">import</span> 包名.模块名</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> 包名 <span class="keyword">import</span> *</span><br></pre></td></tr></table></figure>
<ul class="lvl-0">
<li class="lvl-2">
<p><code>__all__ = []</code> :允许导入的模块或功能列表</p>
</li>
</ul>
</article><div class="post-tools" id="post-tools"><div class="post-tools-left"><div class="rewardLeftButton"><div class="post-reward" onclick="anzhiyu.addRewardMask()"><div class="reward-button button--animated" title="赞赏作者"><i class="anzhiyufont anzhiyu-icon-hand-heart-fill"></i>打赏作者</div><div class="reward-main"><div class="reward-all"><span class="reward-title">感谢你赐予我前进的力量</span><ul class="reward-group"><li class="reward-item"><a href="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/wx.2a62ljcc2n40.png" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/wx.2a62ljcc2n40.png" alt="wechat"/></a><div class="post-qr-code-desc">wechat</div></li><li class="reward-item"><a href="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/zfb.23605lp4hi1s.png" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/zfb.23605lp4hi1s.png" alt="alipay"/></a><div class="post-qr-code-desc">alipay</div></li></ul><a class="reward-main-btn" href="/about/#about-reward" target="_blank"><div class="reward-text">赞赏者名单</div><div class="reward-dec">因为你们的支持让我意识到写文章的价值🙏</div></a></div></div><div id="quit-box" onclick="anzhiyu.removeRewardMask()" style="display: none"></div></div></div><div class="shareRight"><div class="share-link mobile"><div class="share-qrcode"><div class="share-button" title="使用手机访问这篇文章"><i class="anzhiyufont anzhiyu-icon-qrcode"></i></div><div class="share-main"><div class="share-main-all"><div id="qrcode" title="https://www.beidaoaz.top/pythonadv_OOP_5.html"></div><div class="reward-dec">使用手机访问这篇文章</div></div></div></div></div><div class="share-link weibo"><a class="share-button" target="_blank" href="https://service.weibo.com/share/share.php?title=Python进阶(五)模块和包&url=https://www.beidaoaz.top/pythonadv_OOP_5.html&pic=https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png" rel="external nofollow noreferrer noopener"><i class="anzhiyufont anzhiyu-icon-weibo"></i></a></div><div class="share-link copyurl"><div class="share-button" id="post-share-url" title="复制链接" onclick="rm.copyPageUrl()"><i class="anzhiyufont anzhiyu-icon-link"></i></div></div></div></div><div class="post-tools-right"><div class="tag_share"><div class="post-meta__box"><div class="post-meta__box__tag-list"><a class="post-meta__box__tags" href="tags/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/"><span class="tags-punctuation"><i class="anzhiyufont anzhiyu-icon-tag"></i></span>面向对象编程<span class="tagsPageCount">6</span></a><a class="post-meta__box__tags" href="tags/Python%E8%BF%9B%E9%98%B6/"><span class="tags-punctuation"><i class="anzhiyufont anzhiyu-icon-tag"></i></span>Python进阶<span class="tagsPageCount">6</span></a></div></div></div><div class="post_share"><div class="social-share" data-image="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@Science+/read_paper/1.kupf912yxi8.webp" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://npm.elemecdn.com/[email protected]/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"/><script src="https://npm.elemecdn.com/[email protected]/sharejs/dist/js/social-share.min.js" defer="defer"></script></div></div></div><div class="post-copyright"><i class="anzhiyufont anzhiyu-icon-copyright"></i><div class="post-copyright__author"><a class="post-copyright__original" title="该文章为原创文章,注意版权协议" href="https://www.beidaoaz.top/pythonadv_OOP_5.html">原创</a><a class="post-copyright-title"><span>Python进阶(五)模块和包</span></a></div><div class="post-copyright-info-box"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"></span><a class="link" href="https://www.beidaoaz.top">Beidaos</a></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a class="link" href="https://www.beidaoaz.top/pythonadv_OOP_5.html">https://www.beidaoaz.top/pythonadv_OOP_5.html</a></span><span class="copy-button" onclick="rm.copyPageUrl()"><i class="anzhiyufont anzhiyu-icon-copy"></i></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外,均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="external nofollow noreferrer" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="https://www.beidaoaz.top" target="_blank">BEIDAO.</a>!</span></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="pythonadv_OOP_4.html"><img class="prev-cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Python进阶(四)异常</div></div></a></div><div class="next-post pull-right"><a href="pythonadv_OOP_6.html"><img class="next-cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Python进阶(六)案例:面向对象版学员管理系统</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="anzhiyufont anzhiyu-icon-thumbs-up fa-fw" style="font-size: 1.5rem; margin-right: 4px"></i><span>相关推荐</span></div><div class="relatedPosts-list"><div><a href="pythonadv_OOP_2.html" title="Python进阶(二)面向对象—继承"><img class="cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2023-07-05</div><div class="title">Python进阶(二)面向对象—继承</div></div></a></div><div><a href="pythonadv_OOP_1.html" title="Python进阶(一)面向对象基础"><img class="cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2023-07-04</div><div class="title">Python进阶(一)面向对象基础</div></div></a></div><div><a href="pythonadv_OOP_6.html" title="Python进阶(六)案例:面向对象版学员管理系统"><img class="cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2023-07-09</div><div class="title">Python进阶(六)案例:面向对象版学员管理系统</div></div></a></div><div><a href="pythonadv_OOP_4.html" title="Python进阶(四)异常"><img class="cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2023-07-08</div><div class="title">Python进阶(四)异常</div></div></a></div><div><a href="pythonadv_OOP_3.html" title="Python进阶(三)面向对象—多态、类方法、类属性"><img class="cover" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png" alt="cover"><div class="content is-center"><div class="date"><i class="anzhiyufont anzhiyu-icon-calendar-days fa-fw"></i> 2023-07-06</div><div class="title">Python进阶(三)面向对象—多态、类方法、类属性</div></div></a></div></div></div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="anzhiyufont anzhiyu-icon-comments"></i><span> 评论</span></div><div class="comment-randomInfo" style="display: none"><a onclick="anzhiyu.addRandomCommentInfo()" href="javascript:void(0)" rel="external nofollow noreferrer">匿名评论</a></div><div class="comment-tips" id="comment-tips"><span>你无需删除空行,直接评论以获取最佳展示效果</span></div></div><div class="comment-wrap"><div><div id="twikoo-wrap"></div></div></div><div class="comment-barrage"></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="author-info-top"> <div class="card-info-avatar"><a class="avatar-img" href="/about"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/avatar.1tq7dqdicpmo.png" onerror="this.onerror=null;this.src='../private_ismg/404.gif'" alt="avatar"/></a></div></div><div class="author-info__sayhi" id="author-info__sayhi"></div><h1 class="author-info__name">Beidaos</h1><div class="author-info__description">Live yourself as a ray of light.</div><div class="card-info-social-icons is-center"><a class="social-icon faa-parent animated-hover" href="https://github.com/AnZhiJJ" rel="external nofollow noreferrer" target="_blank" title="Github"><i class="anzhiyufont anzhiyu-icon-github"></i></a><a class="social-icon faa-parent animated-hover" href="https://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&[email protected]" rel="external nofollow noreferrer" target="_blank" title="Email"><i class="anzhiyufont anzhiyu-icon-envelope"></i></a><a class="social-icon faa-parent animated-hover" href="https://www.ithome.com/" rel="external nofollow noreferrer" target="_blank" title="ItHome"><i class="anzhiyufont anzhiyu-icon-rss"></i></a></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-bars"></i><span>文章目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#%E7%9B%AE%E6%A0%87"><span class="toc-text">目标</span></a></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%80-%E6%A8%A1%E5%9D%97"><span class="toc-text">一. 模块</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-1-%E5%AF%BC%E5%85%A5%E6%A8%A1%E5%9D%97"><span class="toc-text">1.1. 导入模块</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-1-%E5%AF%BC%E5%85%A5%E6%A8%A1%E5%9D%97%E7%9A%84%E6%96%B9%E5%BC%8F"><span class="toc-text">1.1.1 导入模块的方式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-1-2-%E5%AF%BC%E5%85%A5%E6%96%B9%E5%BC%8F%E8%AF%A6%E8%A7%A3"><span class="toc-text">1.1.2 导入方式详解</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1-1-2-1-import"><span class="toc-text">1.1.2.1 import</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-1-2-2-from%E2%80%A6import%E2%80%A6"><span class="toc-text">1.1.2.2 from…import…</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-1-2-3-from-%E2%80%A6-import-%E2%80%94%E2%80%94%E2%80%94%E5%AF%BC%E5%85%A5%E6%A8%A1%E5%9D%97%E6%89%80%E6%9C%89%E4%BB%A3%E7%A0%81%EF%BC%88%E5%90%AB%E5%8A%9F%E8%83%BD%E5%87%BD%E6%95%B0%EF%BC%89"><span class="toc-text">1.1.2.3 from … import * ———导入模块所有代码(含功能函数)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#1-1-2-4-as%E5%AE%9A%E4%B9%89%E5%88%AB%E5%90%8D"><span class="toc-text">1.1.2.4 as定义别名</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-2-%E5%88%B6%E4%BD%9C%E6%A8%A1%E5%9D%97"><span class="toc-text">1.2. 制作模块</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-1-%E5%AE%9A%E4%B9%89%E6%A8%A1%E5%9D%97"><span class="toc-text">1.2.1 定义模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-2-%E6%B5%8B%E8%AF%95%E6%A8%A1%E5%9D%97"><span class="toc-text">1.2.2 测试模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-3-%E8%B0%83%E7%94%A8%E6%A8%A1%E5%9D%97"><span class="toc-text">1.2.3 调用模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#1-2-4-%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9"><span class="toc-text">1.2.4 注意事项</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-3-%E6%A8%A1%E5%9D%97%E5%AE%9A%E4%BD%8D%E9%A1%BA%E5%BA%8F"><span class="toc-text">1.3. 模块定位顺序</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#1-4-all-%E2%80%94%E2%80%94%E5%9C%A8%E6%A8%A1%E5%9D%97%E6%96%87%E4%BB%B6%E4%B8%AD%E8%AE%BE%E7%BD%AE"><span class="toc-text">1.4. __all__——在模块文件中设置</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%BA%8C-%E5%8C%85"><span class="toc-text">二. 包</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#2-1-%E5%88%B6%E4%BD%9C%E5%8C%85"><span class="toc-text">2.1 制作包</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-1-%E7%A4%BA%E4%BE%8B"><span class="toc-text">2.1.1 示例</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-2-%E5%AF%BC%E5%85%A5%E5%8C%85"><span class="toc-text">2.2 导入包</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-1-%E6%96%B9%E6%B3%95%E4%B8%80"><span class="toc-text">2.2.1 方法一</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#2-2-1-1-%E7%A4%BA%E4%BE%8B"><span class="toc-text">2.2.1.1 示例</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-2-%E6%96%B9%E6%B3%95%E4%BA%8C"><span class="toc-text">2.2.2 方法二</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#2-2-2-1-%E7%A4%BA%E4%BE%8B"><span class="toc-text">2.2.2.1 示例</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link" href="#%E4%B8%89-%E6%80%BB%E7%BB%93"><span class="toc-text">三. 总结</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="" title="卷积神经网络-CNN"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@Science+/read_paper/1.kupf912yxi8.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="卷积神经网络-CNN"/></a><div class="content"><a class="title" href="" title="卷积神经网络-CNN">卷积神经网络-CNN</a><time datetime="2023-07-26T00:00:00.000Z" title="发表于 2023-07-26 08:00:00">2023-07-26</time></div></div><div class="aside-list-item"><a class="thumbnail" href="deepLearning02.html" title="神经网络中的反向传播算法——BackPropagation算法"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@Science+/read_paper/1.kupf912yxi8.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="神经网络中的反向传播算法——BackPropagation算法"/></a><div class="content"><a class="title" href="deepLearning02.html" title="神经网络中的反向传播算法——BackPropagation算法">神经网络中的反向传播算法——BackPropagation算法</a><time datetime="2023-07-25T10:00:00.000Z" title="发表于 2023-07-25 18:00:00">2023-07-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="deepLearning01.html" title="神经网络基础"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@Science+/read_paper/1.kupf912yxi8.webp" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="神经网络基础"/></a><div class="content"><a class="title" href="deepLearning01.html" title="神经网络基础">神经网络基础</a><time datetime="2023-07-25T00:00:00.000Z" title="发表于 2023-07-25 08:00:00">2023-07-25</time></div></div><div class="aside-list-item"><a class="thumbnail" href="latex1.html" title="【LaTeX】新手教程:从入门到日常使用"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/image.3qlx7labk120.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="【LaTeX】新手教程:从入门到日常使用"/></a><div class="content"><a class="title" href="latex1.html" title="【LaTeX】新手教程:从入门到日常使用">【LaTeX】新手教程:从入门到日常使用</a><time datetime="2023-07-23T03:00:00.000Z" title="发表于 2023-07-23 11:00:00">2023-07-23</time></div></div><div class="aside-list-item"><a class="thumbnail" href="pythonadv_OOP_6.html" title="Python进阶(六)案例:面向对象版学员管理系统"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Python进阶(六)案例:面向对象版学员管理系统"/></a><div class="content"><a class="title" href="pythonadv_OOP_6.html" title="Python进阶(六)案例:面向对象版学员管理系统">Python进阶(六)案例:面向对象版学员管理系统</a><time datetime="2023-07-09T00:00:00.000Z" title="发表于 2023-07-09 08:00:00">2023-07-09</time></div></div><div class="aside-list-item"><a class="thumbnail" href="pythonadv_OOP_5.html" title="Python进阶(五)模块和包"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.statically.io/gh/AnZhiJJ/Blog_Img@main/博客站点配图/python-logo.6puefdh4wtk0.png" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Python进阶(五)模块和包"/></a><div class="content"><a class="title" href="pythonadv_OOP_5.html" title="Python进阶(五)模块和包">Python进阶(五)模块和包</a><time datetime="2023-07-09T00:00:00.000Z" title="发表于 2023-07-09 08:00:00">2023-07-09</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div id="footer_deal"><a class="deal_link" href="../mailto:[email protected]" title="email"><i class="anzhiyufont anzhiyu-icon-envelope"></i></a><a class="deal_link" target="_blank" rel="noopener external nofollow noreferrer" href="https://weibo.com/u/2792503557" title="微博"><i class="anzhiyufont anzhiyu-icon-weibo"></i></a><img class="footer_mini_logo" title="返回顶部" onclick="anzhiyu.scrollToDest(0, 500)" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/avatar.1tq7dqdicpmo.png"/><a class="deal_link" target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/AnZhiJJ" title="Github"><i class="anzhiyufont anzhiyu-icon-github"></i></a><a class="deal_link" target="_blank" rel="noopener external nofollow noreferrer" href="https://space.bilibili.com/360398463" title="Bilibili"><i class="anzhiyufont anzhiyu-icon-bilibili"></i></a></div></div><div id="ah-footer"><div class="footer-group"><h3 class="footer-title">博客文章</h3><div class="footer-links"><a class="footer-item" href="/archives/" data-pjax-state="">全部文章</a><a class="footer-item" href="/tags/" data-pjax-state="">文章标签</a><a class="footer-item" href="/categories/" data-pjax-state="">文章分类</a></div></div><div class="footer-group"><h3 class="footer-title">学习笔记</h3><div class="footer-links"><a class="footer-item" href="/categories/C语法/" data-pjax-state="">C 语法</a><a class="footer-item" href="/categories/Python语法/" data-pjax-state="">Python语法</a><a class="footer-item" href="/categories/技术文档/" data-pjax-state="">技术文档</a></div></div><div class="footer-group"><h3 class="footer-title">博客链接</h3><div class="footer-links"><a class="footer-item" href="/album/" data-pjax-state="">相册集</a><a class="footer-item" href="/collect/" data-pjax-state="">藏宝阁</a><a class="footer-item" href="/essay/" data-pjax-state="">闲言碎语</a></div></div><div class="footer-group"><h3 class="footer-title">关于本站</h3><div class="footer-links"><a class="footer-item" href="/about/" data-pjax-state="">关于博主</a><a class="footer-item" href="/cc/" data-pjax-state="">版权协议</a></div></div></div><div id="fotter-copyright" style="font-size:100%"><div class="copyrights"><span>Copyright © 2022 Beidaos. </span><span> All rights reserved.</span></div><div class="framework-info"><span>Powered by </span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://hexo.io">Hexo</a><span class="footer-separator">&</span><a target="_blank" rel="noopener external nofollow noreferrer" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/avatar.1tq7dqdicpmo.png" onerror="onerror=null;src='/private_ismg/404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="archives/" title="archive"><div class="headline">文章</div><div class="length-num">32</div></a><a href="tags/" title="tag"><div class="headline">标签</div><div class="length-num">16</div></a><a href="categories/" title="category"><div class="headline">分类</div><div class="length-num">8</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><span> 文章</span></a><ul class="menus_item_child" style="left:-79px;"><li><a class="site-page child faa-parent animated-hover" href="/archives/"><i class="anzhiyufont anzhiyu-icon-box-archive faa-tada" style="font-size: 0.9em;"></i><span> 归档</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/categories/"><i class="anzhiyufont anzhiyu-icon-shapes faa-tada" style="font-size: 0.9em;"></i><span> 分类</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/tags/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-biaoqiantags3"></use></svg><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><span> 社交</span></a><ul class="menus_item_child" style="left:-31px;"><li><a class="site-page child faa-parent animated-hover" href="/link/"><i class="anzhiyufont anzhiyu-icon-link faa-tada" style="font-size: 0.9em;"></i><span> 友链</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/essay/"><i class="anzhiyufont anzhiyu-icon-lightbulb faa-tada" style="font-size: 0.9em;"></i><span> 闲言碎语</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><span> 我的</span></a><ul class="menus_item_child" style="left:-79px;"><li><a class="site-page child faa-parent animated-hover" href="/music/?id=886726002&server=netease"><i class="anzhiyufont anzhiyu-icon-music faa-tada" style="font-size: 0.9em;"></i><span> 音乐馆</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/collect/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-dropboxdropbox4"></use></svg><span> 藏宝阁</span></a></li><li><a class="site-page child faa-parent animated-hover" href="/album/"><i class="anzhiyufont anzhiyu-icon-images faa-tada" style="font-size: 0.9em;"></i><span> 相册集</span></a></li></ul></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="javascript:void(0);" rel="external nofollow noreferrer"><span> 关于</span></a><ul class="menus_item_child" style="left:17px;"><li><a class="site-page child faa-parent animated-hover" href="/about/"><i class="anzhiyufont anzhiyu-icon-paper-plane faa-tada" style="font-size: 0.9em;"></i><span> 关于博主</span></a></li></ul></div></div></div></div><div id="keyboard-tips"><div class="keyboardTitle">博客快捷键</div><div class="keybordList"><div class="keybordItem"><div class="keyGroup"><div class="key">shift K</div></div><div class="keyContent"><div class="content">关闭快捷键功能</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift A</div></div><div class="keyContent"><div class="content">打开中控台</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift M</div></div><div class="keyContent"><div class="content">播放/暂停音乐</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift D</div></div><div class="keyContent"><div class="content">深色/浅色显示模式</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift S</div></div><div class="keyContent"><div class="content">站内搜索</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift R</div></div><div class="keyContent"><div class="content">随机访问</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift H</div></div><div class="keyContent"><div class="content">返回首页</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift F</div></div><div class="keyContent"><div class="content">友链鱼塘</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift L</div></div><div class="keyContent"><div class="content">友链页面</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift P</div></div><div class="keyContent"><div class="content">关于本站</div></div></div><div class="keybordItem"><div class="keyGroup"><div class="key">shift I</div></div><div class="keyContent"><div class="content">原版右键菜单</div></div></div></div></div><script>var anzhiyu_keyboard = false
var anzhiyu_intype = false
var anzhiyu_keyUpEvent_timeoutId = null
function addKeyShotListener() {
const windowObject = window;
windowObject.removeEventListener("keydown", keyDownEvent);
windowObject.removeEventListener("keyup", keyUpEvent);
windowObject.addEventListener("keydown", keyDownEvent);
windowObject.addEventListener("keyup", keyUpEvent);
}
function keyDownEvent(event) {
const isEscapeKeyPressed = event.keyCode === 27;
const isShiftKeyPressed = event.shiftKey;
const isKeyboardEnabled = anzhiyu_keyboard;
const isInInputField = anzhiyu_intype;
if (isEscapeKeyPressed) {
anzhiyu.hideLoading();
anzhiyu.hideConsole();
rm.hideRightMenu();
}
if (isKeyboardEnabled && isShiftKeyPressed && !isInInputField) {
switch (event.keyCode) {
case 16:
anzhiyu_keyUpEvent_timeoutId = setTimeout(()=>{
document.querySelector("#keyboard-tips").classList.add("show");
}, 200);
break;
case 65:
anzhiyu.showConsole();
break;
case 77:
anzhiyu.musicToggle();
case 75:
anzhiyu.keyboardToggle();
case 73:
anzhiyu.rightMenuToggle();
break;
case 82:
toRandomPost();
break;
case 72:
pjax.loadUrl("/");
break;
case 68:
rm.switchDarkMode();
break;
case 70:
pjax.loadUrl("/fcircle/");
break;
case 76:
pjax.loadUrl("/link/");
break;
case 80:
pjax.loadUrl("/about/");
break;
default:
break;
}
event.preventDefault();
}
}
addKeyShotListener();
window.onfocus = function() {
document.getElementById("keyboard-tips").classList.remove("show")
}
function setInputFocusListener() {
const inputs = document.querySelectorAll("input, textarea");
inputs.forEach((input) => {
input.addEventListener("focus", () => {
setAnzhiyuIntype(true);
});
input.addEventListener("blur", () => {
setAnzhiyuIntype(false);
});
});
}
function setanzhiyuIntype(value) {
anzhiyu_intype = value;
}
function keyUpEvent(event) {
anzhiyu_keyUpEvent_timeoutId && clearTimeout(anzhiyu_keyUpEvent_timeoutId);
if (event.keyCode === 16) {
const keyboardTips = document.querySelector("#keyboard-tips");
keyboardTips.classList.remove("show");
}
}
function listenToPageInputPress() {
const inputElement = document.getElementById("toPageText");
const buttonElement = document.getElementById("toPageButton");
if (!inputElement) {
return;
}
inputElement.addEventListener("keydown", (event) => {
if (event.keyCode === 13) {
event.preventDefault();
anzhiyu.toPage();
pjax.loadUrl(buttonElement.href);
}
});
inputElement.addEventListener("input", () => {
const value = inputElement.value;
if (!value || value === "0") {
buttonElement.classList.remove("haveValue");
} else {
buttonElement.classList.add("haveValue");
}
const pageNumbers = document.querySelectorAll(".page-number");
const maxPageNumber = +pageNumbers[pageNumbers.length - 1].innerHTML;
if (+value > maxPageNumber) {
inputElement.value = maxPageNumber;
}
});
}
setInputFocusListener()</script><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="anzhiyufont anzhiyu-icon-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button type="button" title="切换背景" onclick="toggleWinbox()"><i class="iconfont icon-qiehuankapian"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="anzhiyufont anzhiyu-icon-circle-half-stroke"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="anzhiyufont anzhiyu-icon-arrows-left-right"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="anzhiyufont anzhiyu-icon-gear"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="anzhiyufont anzhiyu-icon-list-ul"></i></button><a id="to_comment" href="#post-comment" title="直达评论"><i class="anzhiyufont anzhiyu-icon-comments"></i></a><a id="switch_commentBarrage" href="javascript:anzhiyu.switchCommentBarrage();" rel="external nofollow noreferrer" title="开关弹幕"><i class="anzhiyufont anzhiyu-icon-danmu"></i></a><button id="center-console" type="button" title="中控台"><i class="iconfont icon-kongzhitai"></i></button><button id="go-up" type="button" title="回到顶部"><i class="anzhiyufont anzhiyu-icon-arrow-up"></i></button></div></div><div id="nav-music"><div id="nav-music-hoverTips" onclick="anzhiyu.musicToggle()">播放音乐</div><div id="console-music-bg"></div><meting-js id="886726002" server="netease" type="playlist" mutex="true" preload="none" theme="var(--anzhiyu-main)" data-lrctype="0" order="random"></meting-js></div><div id="console"><div class="close-btn" onclick="anzhiyu.hideConsole()" href="javascript:void(0);"><i class="anzhiyufont anzhiyu-icon-circle-xmark" style="font-size: 35px;"></i></div><div class="console-card-group-reward"><ul class="reward-all console-card"><li class="reward-item"><a href="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/wx.2a62ljcc2n40.png" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" alt="wechat" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/wx.2a62ljcc2n40.png"/></a><div class="post-qr-code-desc">wechat</div></li><li class="reward-item"><a href="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/zfb.23605lp4hi1s.png" rel="external nofollow noreferrer" target="_blank"><img class="post-qr-code-img" alt="alipay" src= "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-lazy-src="https://cdn.staticaly.com/gh/AnZhiJJ/Blog_Img@main/博客站点配图/zfb.23605lp4hi1s.png"/></a><div class="post-qr-code-desc">alipay</div></li></ul></div><div class="console-card-group"><div class="console-card-group-left"><div class="console-card" id="card-newest-comments" onclick="anzhiyu.hideConsole()"><div class="card-content"><div class="author-content-item-tips">互动</div><span class="author-content-item-title"> <span>最新评论</span></span></div><div class="aside-list"><span>正在加载中...</span></div></div></div><div class="console-card-group-right"><div class="console-card tags" onclick="anzhiyu.hideConsole()"><div class="card-content"><div class="author-content-item-tips">兴趣点</div><span class="author-content-item-title">寻找你感兴趣的领域</span><div class="card-tags"><div class="item-headline"></div><div class="card-tag-cloud"><a href="tags/BP%E7%AE%97%E6%B3%95/" style="font-size: 1.05rem;">BP算法<sup>1</sup></a><a href="tags/Catia/" style="font-size: 1.05rem;">Catia<sup>1</sup></a><a href="tags/C%E8%AF%AD%E6%B3%95/" style="font-size: 1.05rem; font-weight: 500; color: var(--anzhiyu-lighttext)">C语法<sup>2</sup></a><a href="tags/DNS/" style="font-size: 1.05rem;">DNS<sup>1</sup></a><a href="tags/LaTeX/" style="font-size: 1.05rem;">LaTeX<sup>1</sup></a><a href="tags/Python%E8%AF%AD%E6%B3%95/" style="font-size: 1.05rem; font-weight: 500; color: var(--anzhiyu-lighttext)">Python语法<sup>16</sup></a><a href="tags/Python%E8%BF%9B%E9%98%B6/" style="font-size: 1.05rem;">Python进阶<sup>6</sup></a><a href="tags/conda/" style="font-size: 1.05rem;">conda<sup>1</sup></a><a href="tags/pip/" style="font-size: 1.05rem;">pip<sup>1</sup></a><a href="tags/%E5%8D%B7%E7%A7%AF%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C/" style="font-size: 1.05rem;">卷积神经网络<sup>1</sup></a><a href="tags/%E5%9F%9F%E5%90%8D%E8%A7%A3%E6%9E%90/" style="font-size: 1.05rem;">域名解析<sup>1</sup></a><a href="tags/%E6%8C%87%E9%92%88/" style="font-size: 1.05rem;">指针<sup>1</sup></a><a href="tags/%E6%96%87%E7%8C%AE%E7%AC%94%E8%AE%B0/" style="font-size: 1.05rem;">文献笔记<sup>1</sup></a><a href="tags/%E6%B7%B1%E5%BA%A6%E5%AD%A6%E4%B9%A0/" style="font-size: 1.05rem;">深度学习<sup>3</sup></a><a href="tags/%E7%A5%9E%E7%BB%8F%E7%BD%91%E7%BB%9C/" style="font-size: 1.05rem;">神经网络<sup>1</sup></a><a href="tags/%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/" style="font-size: 1.05rem;">面向对象编程<sup>6</sup></a></div></div><hr/></div></div><div class="console-card history" onclick="anzhiyu.hideConsole()"><div class="item-headline"><i class="anzhiyufont anzhiyu-icon-box-archiv"></i><span>文章</span></div></div></div></div><div class="button-group"><div class="console-btn-item"><a class="darkmode_switchbutton" onclick="rm.switchDarkMode()" title="显示模式切换" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="anzhiyufont anzhiyu-icon-moon"></i></a></div><div class="console-btn-item" id="consoleHideAside" onclick="anzhiyu.hideAsideBtn()" title="边栏显示控制"><a class="asideSwitch"><i class="anzhiyufont anzhiyu-icon-arrows-left-right"></i></a></div><div class="console-btn-item on" id="consoleCommentBarrage" onclick="anzhiyu.switchCommentBarrage()" title="热评开关"><a class="commentBarrage"><i class="anzhiyufont anzhiyu-icon-message"></i></a></div><div class="console-btn-item" id="consoleMusic" onclick="anzhiyu.musicToggle()" title="音乐开关"><a class="music-switch"><i class="anzhiyufont anzhiyu-icon-music"></i></a></div><div class="console-btn-item" id="consoleKeyboard" onclick="anzhiyu.keyboardToggle()" title="快捷键开关"><a class="keyboard-switch"><i class="anzhiyufont anzhiyu-icon-keyboard"></i></a></div></div><div class="console-mask" onclick="anzhiyu.hideConsole()" href="javascript:void(0);" rel="external nofollow noreferrer"></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="anzhiyufont anzhiyu-icon-xmark"></i></button></nav><div class="is-center" id="loading-database"><i class="anzhiyufont anzhiyu-icon-spinner anzhiyu-pulse-icon"></i><span> 数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div id="rightMenu"><div class="rightMenu-group rightMenu-small"><div class="rightMenu-item" id="menu-backward"><i class="anzhiyufont anzhiyu-icon-arrow-left"></i></div><div class="rightMenu-item" id="menu-forward"><i class="anzhiyufont anzhiyu-icon-arrow-right"></i></div><div class="rightMenu-item" id="menu-refresh"><i class="anzhiyufont anzhiyu-icon-arrow-rotate-right" style="font-size: 1rem;"></i></div><div class="rightMenu-item" id="menu-top"><i class="anzhiyufont anzhiyu-icon-arrow-up"></i></div></div><div class="rightMenu-group rightMenu-line rightMenuPlugin"><div class="rightMenu-item" id="menu-copytext"><i class="anzhiyufont anzhiyu-icon-copy"></i><span>复制选中文本</span></div><div class="rightMenu-item" id="menu-pastetext"><i class="anzhiyufont anzhiyu-icon-paste"></i><span>粘贴文本</span></div><a class="rightMenu-item" id="menu-commenttext"><i class="anzhiyufont anzhiyu-icon-comment-medical"></i><span>引用到评论</span></a><div class="rightMenu-item" id="menu-newwindow"><i class="anzhiyufont anzhiyu-icon-window-restore"></i><span>新窗口打开</span></div><div class="rightMenu-item" id="menu-copylink"><i class="anzhiyufont anzhiyu-icon-link"></i><span>复制链接地址</span></div><div class="rightMenu-item" id="menu-copyimg"><i class="anzhiyufont anzhiyu-icon-images"></i><span>复制此图片</span></div><div class="rightMenu-item" id="menu-downloadimg"><i class="anzhiyufont anzhiyu-icon-download"></i><span>下载此图片</span></div><div class="rightMenu-item" id="menu-newwindowimg"><i class="anzhiyufont anzhiyu-icon-window-restore"></i><span>新窗口打开图片</span></div><div class="rightMenu-item" id="menu-search"><i class="anzhiyufont anzhiyu-icon-magnifying-glass"></i><span>站内搜索</span></div><div class="rightMenu-item" id="menu-searchBaidu"><i class="anzhiyufont anzhiyu-icon-magnifying-glass"></i><span>百度搜索</span></div><div class="rightMenu-item" id="menu-music-toggle"><i class="anzhiyufont anzhiyu-icon-play"></i><span>播放音乐</span></div><div class="rightMenu-item" id="menu-music-back"><i class="anzhiyufont anzhiyu-icon-backward"></i><span>切换到上一首</span></div><div class="rightMenu-item" id="menu-music-forward"><i class="anzhiyufont anzhiyu-icon-forward"></i><span>切换到下一首</span></div><div class="rightMenu-item" id="menu-music-playlist" onclick="window.open("https://music.163.com/#/my/m/music/playlist?id=886726002", "_blank");" style="display: none;"><i class="anzhiyufont anzhiyu-icon-radio"></i><span>查看所有歌曲</span></div><div class="rightMenu-item" id="menu-music-copyMusicName"><i class="anzhiyufont anzhiyu-icon-copy"></i><span>复制歌名</span></div></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item menu-link" id="menu-randomPost"><i class="anzhiyufont anzhiyu-icon-shuffle"></i><span>随便逛逛</span></a><a class="rightMenu-item menu-link" href="/categories/"><i class="anzhiyufont anzhiyu-icon-cube"></i><span>博客分类</span></a><a class="rightMenu-item menu-link" href="/tags/"><i class="anzhiyufont anzhiyu-icon-tags"></i><span>文章标签</span></a></div><div class="rightMenu-group rightMenu-line rightMenuOther"><a class="rightMenu-item" id="menu-copy" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="anzhiyufont anzhiyu-icon-copy"></i><span>复制地址</span></a><a class="rightMenu-item" id="menu-commentBarrage" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="anzhiyufont anzhiyu-icon-message"></i><span class="menu-commentBarrage-text">关闭热评</span></a><a class="rightMenu-item" id="menu-darkmode" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="anzhiyufont anzhiyu-icon-circle-half-stroke"></i><span class="menu-darkmode-text">深色模式</span></a><a class="rightMenu-item" id="menu-translate" href="javascript:void(0);" rel="external nofollow noreferrer"><i class="anzhiyufont anzhiyu-icon-language"></i><span>轉為繁體</span></a></div></div><div id="rightmenu-mask"></div><div><script src="https://npm.elemecdn.com/[email protected]/source/js/utils.js"></script><script src="https://npm.elemecdn.com/[email protected]/source/js/main.js"></script><script src="https://npm.elemecdn.com/[email protected]/source/js/tw_cn.js"></script><script src="https://npm.elemecdn.com/@fancyapps/[email protected]/dist/fancybox.umd.js"></script><script src="https://npm.elemecdn.com/[email protected]/instantpage.js" type="module"></script><script src="https://npm.elemecdn.com/[email protected]/dist/lazyload.iife.min.js"></script><script src="https://npm.elemecdn.com/[email protected]/dist/snackbar.min.js"></script><canvas id="universe"></canvas><script async src="https://npm.elemecdn.com/[email protected]/dark/dark.js"></script><script>// 消除控制台打印
var HoldLog = console.log;
console.log = function () {};
let now1 = new Date();
queueMicrotask(() => {
const Log = function () {
HoldLog.apply(console, arguments);
}; //在恢复前输出日志
const grt = new Date("04/01/2021 00:00:00"); //此处修改你的建站时间或者网站上线时间
now1.setTime(now1.getTime() + 250);
const days = (now1 - grt) / 1000 / 60 / 60 / 24;
const dnum = Math.floor(days);
const ascll = [
`欢迎使用安知鱼!`,
`生活明朗, 万物可爱`,
`
█████╗ ███╗ ██╗███████╗██╗ ██╗██╗██╗ ██╗██╗ ██╗
██╔══██╗████╗ ██║╚══███╔╝██║ ██║██║╚██╗ ██╔╝██║ ██║
███████║██╔██╗ ██║ ███╔╝ ███████║██║ ╚████╔╝ ██║ ██║
██╔══██║██║╚██╗██║ ███╔╝ ██╔══██║██║ ╚██╔╝ ██║ ██║
██║ ██║██║ ╚████║███████╗██║ ██║██║ ██║ ╚██████╔╝
╚═╝ ╚═╝╚═╝ ╚═══╝╚══════╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝
`,
"已上线",
dnum,
"天",
"©2022 By 安知鱼",
];
const ascll2 = [`NCC2-036`, `调用前置摄像头拍照成功,识别为【小笨蛋】.`, `Photo captured: `, `🤪`];
setTimeout(
Log.bind(
console,
`\n%c${ascll[0]} %c ${ascll[1]} %c ${ascll[2]} %c${ascll[3]}%c ${ascll[4]}%c ${ascll[5]}\n\n%c ${ascll[6]}\n`,
"color:#3b70fc",
"",
"color:#3b70fc",
"color:#3b70fc",
"",
"color:#3b70fc",
""
)
);
setTimeout(
Log.bind(
console,
`%c ${ascll2[0]} %c ${ascll2[1]} %c \n${ascll2[2]} %c\n${ascll2[3]}\n`,
"color:white; background-color:#4fd953",
"",
"",
'background:url("https://npm.elemecdn.com/[email protected]/img/post/common/tinggge.gif") no-repeat;font-size:450%'
)
);
setTimeout(Log.bind(console, "%c WELCOME %c 你好,小笨蛋.", "color:white; background-color:#4f90d9", ""));
setTimeout(
console.warn.bind(
console,
"%c ⚡ Powered by 安知鱼 %c 你正在访问 Beidaos 的博客.",
"color:white; background-color:#f0ad4e",
""
)
);
setTimeout(Log.bind(console, "%c W23-12 %c 你已打开控制台.", "color:white; background-color:#4f90d9", ""));
setTimeout(
console.warn.bind(console, "%c S013-782 %c 你现在正处于监控中.", "color:white; background-color:#d9534f", "")
);
});</script><script async src="/anzhiyu/random.js"></script><script src="https://npm.elemecdn.com/[email protected]/source/js/search/local-search.js"></script><div class="js-pjax"><script>(()=>{
const init = () => {
twikoo.init(Object.assign({
el: '#twikoo-wrap',
envId: 'https://twikoo.beidaoaz.top/',
region: '',
onCommentLoaded: function () {
anzhiyu.loadLightbox(document.querySelectorAll('#twikoo .tk-content img:not(.tk-owo-emotion)'))
}
}, null))
}
const getCount = () => {
const countELement = document.getElementById('twikoo-count')
if(!countELement) return
twikoo.getCommentsCount({
envId: 'https://twikoo.beidaoaz.top/',
region: '',
urls: [window.location.pathname],
includeReply: false
}).then(function (res) {
countELement.innerText = res[0].count
}).catch(function (err) {
console.error(err);
});
}
const runFn = () => {
init()
}
const loadTwikoo = () => {
if (typeof twikoo === 'object') {
setTimeout(runFn,0)
return
}
getScript('https://npm.elemecdn.com/[email protected]/dist/twikoo.all.min.js').then(runFn)
}
if ('Twikoo' === 'Twikoo' || !false) {
if (false) anzhiyu.loadComment(document.getElementById('twikoo-wrap'), loadTwikoo)
else loadTwikoo()
} else {
window.loadOtherComment = () => {
loadTwikoo()
}
}
})()</script><input type="hidden" name="page-type" id="page-type" value="post"></div><script>window.addEventListener('load', () => {
const changeContent = (content) => {
if (content === '') return content
content = content.replace(/<img.*?src="(.*?)"?[^\>]+>/ig, '[图片]') // replace image link
content = content.replace(/<a[^>]+?href=["']?([^"']+)["']?[^>]*>([^<]+)<\/a>/gi, '[链接]') // replace url
content = content.replace(/<pre><code>.*?<\/pre>/gi, '[代码]') // replace code
content = content.replace(/<[^>]+>/g,"") // remove html tag
if (content.length > 150) {
content = content.substring(0,150) + '...'
}
return content
}
const getComment = () => {
const runTwikoo = () => {
twikoo.getRecentComments({
envId: 'https://twikoo.beidaoaz.top/',
region: '',
pageSize: 6,
includeReply: true
}).then(function (res) {
const twikooArray = res.map(e => {
return {
'content': changeContent(e.comment),
'avatar': e.avatar,
'nick': e.nick,
'url': e.url + '#' + e.id,
'date': new Date(e.created).toISOString()
}
})
saveToLocal.set('twikoo-newest-comments', JSON.stringify(twikooArray), 10/(60*24))
generateHtml(twikooArray)
}).catch(function (err) {
const $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML= "无法获取评论,请确认相关配置是否正确"
})
}
if (typeof twikoo === 'object') {
runTwikoo()
} else {
getScript('https://npm.elemecdn.com/[email protected]/dist/twikoo.all.min.js').then(runTwikoo)
}
}
const generateHtml = array => {
let result = ''
if (array.length) {
for (let i = 0; i < array.length; i++) {
result += '<div class=\'aside-list-item\'>'
if (true) {
const name = 'data-lazy-src'
result += `<a href='${array[i].url}' class='thumbnail'><img ${name}='${array[i].avatar}' alt='${array[i].nick}'><div class='name'><span>${array[i].nick}</span></div></a>`
}
result += `<div class='content'>
<a class='comment' href='${array[i].url}' title='${array[i].content}'>${array[i].content}</a>
<time datetime="${array[i].date}">${anzhiyu.diffDate(array[i].date, true)}</time></div>
</div>`
}
} else {
result += '没有评论'
}
let $dom = document.querySelector('#card-newest-comments .aside-list')
$dom.innerHTML= result
window.lazyLoadInstance && window.lazyLoadInstance.update()
window.pjax && window.pjax.refresh($dom)
}
const newestCommentInit = () => {
if (document.querySelector('#card-newest-comments .aside-list')) {
const data = saveToLocal.get('twikoo-newest-comments')
if (data) {
generateHtml(JSON.parse(data))
} else {
getComment()
}
}
}
newestCommentInit()
document.addEventListener('pjax:complete', newestCommentInit)
})</script><script async data-pjax src="https://npm.elemecdn.com/[email protected]/bubble/bubble.js"></script><script data-pjax="true">if (document.querySelector(".comment-barrage")){
var commentBarrageConfig = {
maxBarrage: 1,
barrageTime: 4000,
twikooUrl: "https://twikoo.beidaoaz.top/",
accessToken: "",
pageUrl: window.location.pathname,
barrageTimer: [],
barrageList: [],
barrageIndex: 0,
dom: document.querySelector(".comment-barrage"),
};
var commentInterval = null;
var hoverOnCommentBarrage = false;
document.querySelector(".comment-barrage").addEventListener("mouseenter", function() {
hoverOnCommentBarrage = true;
console.log("热评悬浮");
});
document.querySelector(".comment-barrage").addEventListener("mouseleave", function() {
hoverOnCommentBarrage = false;
console.log("停止悬浮");
});
function initCommentBarrage() {
if (!commentBarrageConfig.dom) return;
var data = JSON.stringify({
event: "COMMENT_GET",
"commentBarrageConfig.accessToken": commentBarrageConfig.accessToken,
url: commentBarrageConfig.pageUrl,
});
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function () {
if (this.readyState === 4 && this.responseText) {
commentBarrageConfig.barrageList = commentLinkFilter(JSON.parse(this.responseText).data);
commentBarrageConfig.dom.innerHTML = "";
}
});
xhr.open("POST", commentBarrageConfig.twikooUrl);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
clearInterval(commentInterval);
commentInterval = null;
commentInterval = setInterval(() => {
if (commentBarrageConfig.barrageList.length && !hoverOnCommentBarrage) {
popCommentBarrage(commentBarrageConfig.barrageList[commentBarrageConfig.barrageIndex]);
commentBarrageConfig.barrageIndex += 1;
commentBarrageConfig.barrageIndex %= commentBarrageConfig.barrageList.length;
}
if (
commentBarrageConfig.barrageTimer.length >
(commentBarrageConfig.barrageList.length > commentBarrageConfig.maxBarrage
? commentBarrageConfig.maxBarrage
: commentBarrageConfig.barrageList.length) &&
!hoverOnCommentBarrage
) {
removeCommentBarrage(commentBarrageConfig.barrageTimer.shift());
}
}, commentBarrageConfig.barrageTime);
}
function commentLinkFilter(data) {
data.sort((a, b) => {
return a.created - b.created;
});
let newData = [];
data.forEach(item => {
newData.push(...getCommentReplies(item));
});
return newData;
}
function getCommentReplies(item) {
if (item.replies) {
let replies = [item];
item.replies.forEach(item => {
replies.push(...getCommentReplies(item));
});
return replies;
} else {
return [];
}
}
function popCommentBarrage(data) {
let barrage = document.createElement("div");
barrage.className = "comment-barrage-item";
barrage.innerHTML = `
<div class="barrageHead">
<a class="barrageTitle ${
data.mailMd5 === "d338f432ad0bf2f61e5fe4ad1642725d" ? "barrageBloggerTitle" : ""
}" href="javascript:anzhiyu.scrollTo('#post-comment')"">
${data.mailMd5 === "d338f432ad0bf2f61e5fe4ad1642725d" ? "博主" : "热评"}
</a>
<div class="barrageNick">${data.nick}</div>
<img class="nolazyload barrageAvatar" src="https://cravatar.cn/avatar/${data.mailMd5}"/>
<a class="comment-barrage-close" href="javascript:anzhiyu.switchCommentBarrage()" rel="external nofollow noreferrer"><i class="anzhiyufont anzhiyu-icon-xmark"></i></a>
</div>
<a class="barrageContent" href="#${data.id}">
<object>${data.comment}</object>
</a>
`;
commentBarrageConfig.barrageTimer.push(barrage);
commentBarrageConfig.dom.append(barrage);
}
function removeCommentBarrage(barrage) {
barrage.className = "comment-barrage-item out";
setTimeout(() => {
if (commentBarrageConfig.dom && commentBarrageConfig.dom.contains(barrage)) {
commentBarrageConfig.dom.removeChild(barrage);
}
}, 1000);
}
// 自动隐藏
const commentEntryCallback = (entries) => {
const commentBarrage = document.querySelector(".comment-barrage");
const postComment = document.getElementById("post-comment");
entries.forEach(entry => {
if (postComment && commentBarrage && document.body.clientWidth > 768) {
commentBarrage.style.bottom = entry.isIntersecting ? "-200px" : "0";
}
});
};
// 创建IntersectionObserver实例
const observer = new IntersectionObserver(commentEntryCallback, {
root: null,
rootMargin: "0px",
threshold: 0
});
// 监视目标元素
const postCommentTarget = document.getElementById("post-comment");
if (postCommentTarget) {
observer.observe(postCommentTarget);
}
initCommentBarrage();
if (localStorage.getItem("commentBarrageSwitch") !== "false") {
document.querySelector(".comment-barrage").style.display = "flex";
document.querySelector(".menu-commentBarrage-text").textContent = "关闭热评";
} else {
document.querySelector(".comment-barrage").style.display = "none";
document.querySelector(".menu-commentBarrage-text").textContent = "显示热评";
}
document.addEventListener("pjax:send", function () {
clearInterval(commentInterval);
});
}</script><script data-pjax src="https://npm.elemecdn.com/[email protected]/catalog-bar/catalog-bar.js"></script><script async data-pjax src="https://npm.elemecdn.com/[email protected]/categoryBar/categoryBar.js"></script><script async data-pjax src="https://npm.elemecdn.com/[email protected]/waterfall/waterfall.js"></script><script src="https://lf3-cdn-tos.bytecdntp.com/cdn/expire-1-M/qrcodejs/1.0.0/qrcode.min.js"></script><script>// 初始化函数
let rm = {};
//禁止图片拖拽
let imgElements = document.getElementsByTagName("img");
for (let i = 0; i < imgElements.length; i++) {
imgElements[i].addEventListener("dragstart", function (event) {
event.preventDefault();
});
}
// 显示菜单
rm.showRightMenu = function (isTrue, x = 0, y = 0) {
console.info(x, y)
let rightMenu = document.getElementById("rightMenu");
rightMenu.style.top = x + "px";
rightMenu.style.left = y + "px";
if (isTrue) {
rightMenu.style.display = "block";
stopMaskScroll();
} else {
rightMenu.style.display = "none";
}
};
// 隐藏菜单
rm.hideRightMenu = function () {
rm.showRightMenu(false);
let rightMenuMask = document.querySelector("#rightmenu-mask");
rightMenuMask.style.display = "none";
};
// 尺寸
let rmWidth = document.getElementById("rightMenu").offsetWidth;
let rmHeight = document.getElementById("rightMenu").offsetHeight;
// 重新定义尺寸
rm.reloadrmSize = function () {
rightMenu.style.visibility = "hidden";
rightMenu.style.display = "block";
// 获取宽度和高度
rmWidth = document.getElementById("rightMenu").offsetWidth;
rmHeight = document.getElementById("rightMenu").offsetHeight;
rightMenu.style.visibility = "visible";
};
// 获取点击的href
let domhref = "";
let domImgSrc = "";
let globalEvent = null;
var oncontextmenuFunction = function (event) {
if (document.body.clientWidth > 768) {
let pageX = event.clientX + 10; //加10是为了防止显示时鼠标遮在菜单上
let pageY = event.clientY;
//其他额外菜单
const $rightMenuOther = document.querySelector(".rightMenuOther");
const $rightMenuPlugin = document.querySelector(".rightMenuPlugin");
const $rightMenuCopyText = document.querySelector("#menu-copytext");
const $rightMenuPasteText = document.querySelector("#menu-pastetext");
const $rightMenuCommentText = document.querySelector("#menu-commenttext");
const $rightMenuNewWindow = document.querySelector("#menu-newwindow");
const $rightMenuNewWindowImg = document.querySelector("#menu-newwindowimg");
const $rightMenuCopyLink = document.querySelector("#menu-copylink");
const $rightMenuCopyImg = document.querySelector("#menu-copyimg");
const $rightMenuDownloadImg = document.querySelector("#menu-downloadimg");
const $rightMenuSearch = document.querySelector("#menu-search");
const $rightMenuSearchBaidu = document.querySelector("#menu-searchBaidu");
const $rightMenuMusicToggle = document.querySelector("#menu-music-toggle");
const $rightMenuMusicBack = document.querySelector("#menu-music-back");
const $rightMenuMusicForward = document.querySelector("#menu-music-forward");
const $rightMenuMusicPlaylist = document.querySelector("#menu-music-playlist");
const $rightMenuMusicCopyMusicName = document.querySelector("#menu-music-copyMusicName");
let href = event.target.href;
let imgsrc = event.target.currentSrc;
// 判断模式 扩展模式为有事件
let pluginMode = false;
$rightMenuOther.style.display = "block";
globalEvent = event;
// 检查是否需要复制 是否有选中文本
if (selectTextNow && window.getSelection()) {
pluginMode = true;
$rightMenuCopyText.style.display = "block";
$rightMenuCommentText.style.display = "block";
$rightMenuSearch.style.display = "block";
$rightMenuSearchBaidu.style.display = "block";
} else {
$rightMenuCopyText.style.display = "none";
$rightMenuCommentText.style.display = "none";
$rightMenuSearchBaidu.style.display = "none";
$rightMenuSearch.style.display = "none";
}
//检查是否右键点击了链接a标签
if (href) {
pluginMode = true;
$rightMenuNewWindow.style.display = "block";
$rightMenuCopyLink.style.display = "block";
domhref = href;
} else {
$rightMenuNewWindow.style.display = "none";
$rightMenuCopyLink.style.display = "none";
}
//检查是否需要复制图片
if (imgsrc) {
pluginMode = true;
$rightMenuCopyImg.style.display = "block";
$rightMenuDownloadImg.style.display = "block";
$rightMenuNewWindowImg.style.display = "block";
document.getElementById("rightMenu").style.width="12rem"