Python3 模組、包調用&路徑,python3模組包調用

來源:互聯網
上載者:User

Python3 模組、包調用&路徑,python3模組包調用

 1 ''' 2 以下代碼均為講解,不能實際操作 3 ''' 4 ''' 5 部落格園 Infi_chu 6 ''' 7 ''' 8 模組的優點: 9 1.高可維護性10 2.可以大大減少編寫的代碼量11 12 模組一共有三種:13 1.Python標準庫14 2.第三方模組15 3.應用程式自訂模組16 '''17 # import example  # 調用example模組18 # from example import example # 調用example模組中的一個example方法19 '''20 部落格園 Infi_chu21 '''22 23 24 '''25 包的特點:26 1.有__init__.py檔案27 2.有很多模組組成28 '''29 30 # from test import example    # test為包名,example模組名,一層嵌套31 # from test.test1 import example  # test1、test2均為包名,test1在test中,example為模組名32 # from test.test1.func1 import example    # func1是example模組中的一個func1方法33 # import test     # test為包名,此命令相當於執行了__init__檔案34 '''35 部落格園 Infi_chu36 '''37 '''38 import 包 或 模組 的區別39 import 包 只是執行了一個__init__.py檔案,並沒有與其他模組產生聯絡,取值時需要加.調用40 import 模組 是直接調用模組41 '''42 43 '''44 路徑解決45 '''46 # import sys,os47 # a = os.path.abspath(__file__)       # 得到絕對路徑48 # print(a)49 # print(os.path.dirname(a))       # 得到上一層路徑50 # base_dir = os.path.dirname(os.path.dirname(a))      # 得到上上一層路徑51 # print(base_dir)52 # sys.path.append(base_dir)53 '''54 部落格園 Infi_chu55 '''

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.