import导入模块就是在import的位置将模块(.py)文件拷贝过去 import导入包就是导入包内的__init__.py文件
所以导入一个包时,这个包内一定要有__init__.py文件(必须是其目录的子文件),我们可以借助__init__.py文件导入我们所需的其他模块(当其他模块也是其包的子文件时可以使用from . import module 实现自动子模块导入),也可以借助变量__all__实现from package import *
可以被import导入的对象有:
模块文件(.py文件) C或C++扩展(已编译为共享库或DLL文件) 包(包含多个模块) 内建模块(使用C编写并已链接到Python解释器中)
可以作为模块被导入的文件形式有:.py、.pyo、.pyc、.pyd、.so、.dll
参考:https://blog.csdn.net/m0_37607365/article/details/79889901?utm_medium=distribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-1.pc_relevant_paycolumn&spm=1001.2101.3001.4242.2 https://blog.csdn.net/yucicheung/article/details/79445350
init.py文件:
from .builder import DATASETS, PIPELINES, build_dataloader, build_dataset
from .cityscapes import CityscapesDataset
from .coco import CocoDataset
from .custom import CustomDataset
from .dataset_wrappers import (ClassBalancedDataset, ConcatDataset,
RepeatDataset)
from .deepfashion import DeepFashionDataset
from .lvis import LVISDataset, LVISV1Dataset, LVISV05Dataset
from .nightowls import NightOwlsDataset
from .samplers import DistributedGroupSampler, DistributedSampler, GroupSampler
from .utils import replace_ImageToTensor
from .voc import VOCDataset
from .waymo_open import WaymoOpenDataset
from .wider_face import WIDERFaceDataset
from .xml_style import XMLDataset
from .underwater_optics import UnderwaterOpticsDataset
__all__ = [
'CustomDataset', 'XMLDataset', 'CocoDataset', 'DeepFashionDataset',
'VOCDataset', 'CityscapesDataset', 'LVISDataset', 'LVISV05Dataset',
'LVISV1Dataset', 'GroupSampler', 'DistributedGroupSampler',
'DistributedSampler', 'build_dataloader', 'ConcatDataset', 'RepeatDataset',
'ClassBalancedDataset', 'WIDERFaceDataset', 'DATASETS', 'PIPELINES',
'build_dataset', 'replace_ImageToTensor', 'UnderwaterOpticsDataset'
]
__all__ += ['WaymoOpenDataset', 'NightOwlsDataset']
|