Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法从同一个包导入python模块_Python_Import_Package - Fatal编程技术网

无法从同一个包导入python模块

无法从同一个包导入python模块,python,import,package,Python,Import,Package,我目前正在用python编写一个库。我有一个名为Selectors的包作为库的子目录。我试图在包中实现一个新模块,但当我尝试导入它时,我得到错误: NameError: name '_RaceSelector__ResultSelector' is not defined 我的目录如下所示: Selectors │ ├── __init__.py │ ├── __init__.pyc │ ├── __pycache__ │ │ ├── SeasonSelector.cpyt

我目前正在用python编写一个库。我有一个名为
Selectors
的包作为库的子目录。我试图在包中实现一个新模块,但当我尝试导入它时,我得到错误:

NameError: name '_RaceSelector__ResultSelector' is not defined
我的目录如下所示:

Selectors
│   ├── __init__.py
│   ├── __init__.pyc
│   ├── __pycache__
│   │   ├── SeasonSelector.cpython-38.pyc
│   │   ├── Selector.cpython-38.pyc
│   │   ├── __init__.cpython-38.pyc
│   │   ├── race_selector.cpython-38.pyc
│   │   ├── result_selector.cpython-38.pyc
│   │   └── season_selector.cpython-38.pyc
│   ├── race_selector.py
│   ├── race_selector.pyc
│   ├── result_selector.py
│   ├── result_selector.pyc
│   ├── season_selector.py
│   ├── season_selector.pyc
│   ├── selector.py
│   └── selector.pyc
我想使用
race\u selector.py
中的模块,下面是该文件:

from .selector import __Selector
from .result_selector import __ResultSelector

class RaceSelector(__Selector):

    data = []
    loaded_races = []
    header = []

    result_selector = __ResultSelector()
选择器.py

import os
import csv

class __Selector:
    def __init__(self, file_name):
        self.data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/' + file_name + '.csv')
        self.raw_data = self.load_data()
        self.data = self.get_data()
import os
from .selector import __Selector

class __ResultSelector(__Selector):
    def __init__(self):
        super().__init__('results')
结果_选择器.py

import os
import csv

class __Selector:
    def __init__(self, file_name):
        self.data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data/' + file_name + '.csv')
        self.raw_data = self.load_data()
        self.data = self.get_data()
import os
from .selector import __Selector

class __ResultSelector(__Selector):
    def __init__(self):
        super().__init__('results')
我可以导入
选择器
很好,并按预期工作,但结果选择器会产生错误


感谢您执行以下操作:

result_selector = __ResultSelector()
Python搜索
\u RaceSelector\u ResultSelector
,因为有2个下划线

如中所述:


您确定错误来自result_selector.py吗?因为它提到了
\u RaceSelector
,我在你的代码中找不到它。另外,有什么理由不在一个公共文件中使用不同的选择器吗?哇。我不知道。我也不知道。知道这个很有用。非常感谢。