我有以下目录结构:
V1.0/
module/
answer_type/
__init__.py
worker.py
src/
__init__.py
ans_type/
__init__.py
sent_process.py
module_two/
module_three/
我已将__init__.py
文件放在目录中,以便可以导入它。但它仍然不允许从内部文件中导入类。
sent_process.py
看起来像
from light_lizer.result_initiator import ResultInitiator
import re
import sys
import gearman
import sys,json
class QueryPylinkAnsTypeDetector(GearManOverride):
def __init__(self, config):
super(QueryAnsTypeDetector, self).__init__(config)
self.init_log()
def init_log(self):
print "__init_log"
self.abs_path = os.path.abspath(__file__).replace(os.getcwd(),'').replace('/','-').replace('.py','').replace('.','_')
self.log_set_obj = LogSetting(type(self).__name__)
self.logger = self.log_set_obj.logger
def preProcessLink(self, link):
new_link = link[-2:]
return new_link
def processSentenceSingle(self, read_str):
post_script_link_list = []
linkage[0] = 'xyz'
post_script_link_list = self.preProcessLink(linkage[0])
return result
worker.py
中的我正在尝试从sent_process.py
from src.ans_type.sent_process import QueryPylinkAnsTypeDetector as PylinkProcess
给出错误:from src.answer_type.pylink_process import QueryPylinkAnsTypeDetector
ImportError: No module named src.ans_type.sent_process
有人可以建议这里有什么问题吗?
更新:
在V1.0
目录中,我正在以这种方式执行工作:
python - m module/answer_type/worker