logo
  • 教程列表
  • SO官方文檔
  • 匯入模組
    • 所有特殊變數
    • 匯入模組
    • 從任意檔案系統位置匯入模組
    • 從模組匯入所有名稱
    • 程式化匯入
    • PEP8 匯入規則
    • 從模組匯入特定名稱
    • 匯入子模組
    • import() 函式
    • 重新匯入模組
  1. StackOverflow 文件
  2. Python Language 教程
  3. 匯入模組
  4. import() 函式

import() 函式

Created: November-22, 2018

__import__() 函式可用於匯入名稱僅在執行時已知的模組

if user_input == "os":
    os = __import__("os")

# equivalent to import os

此函式還可用於指定模組的檔案路徑

mod = __import__(r"C:/path/to/file/anywhere/on/computer/module.py")
  • 重新匯入模組
  • 匯入子模組

Copyright © 2018. All right reserved

tastones.com 备案号:鲁ICP备18045372号-1

  • 關於本站
  • 免責聲明