日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

python?import?引用上上上級包的三種方法_python

作者:craftsman2020 ? 更新時間: 2023-06-21 編程語言

方法一

相對引用:

  • from … import base ,上級目錄
  • from … import base,上上級目錄
from ..base import xx

詳細原因請參考:https://www.cnblogs.com/jiaxin359/p/7580375.html

方法二

用sys.path.append

# coding=utf-8 
import sys
import os
CURRENT_DIR = os.path.split(os.path.abspath(__file__))[0]  # 當前目錄
config_path = CURRENT_DIR.rsplit('/', 3)[0]  # 上三級目錄
sys.path.append(config_path)
from config import param
print('config_path=', config_path)
print(sys.path)
print(param)

方法三

用path這個包

import path, sys
folder = path.path(__file__).abspath()
sys.path.append(folder.parent.parent)

原文鏈接:https://blog.csdn.net/craftsman2020/article/details/108277240

  • 上一篇:沒有了
  • 下一篇:沒有了
欄目分類
最近更新