当尝试用pickle加载一个文件时,我得到了ImportError: No module named application_mgmt
。在
奇怪的是,同一个文件可以从一个不同的函数加载,这两个函数甚至都使用相同的get_file方法。奇怪的是,我可以从函数中加载任何其他文件。在
我尝试过将函数移到不同的类/文件中。清除并重新填充保存的文件,但似乎没有任何效果。在
保存文件中的对象:
class Application():
def __init__(self,name,focus=False):
self.name = name
self.focus = focus
self.prod_score = 5
self.display_name = name
self.color = "none"
导致错误的函数:
^{pr2}$文件处理功能:
def get_file(self, file_name):
path = "back/saved_data/%s" % (file_name)
try:
with open(path,'rb') as saved_file:
saved_list = pickle.load(saved_file)
saved_file.close()
return saved_list
except IOError:
#stuff
日志:
Traceback (most recent call last):
File "<stdin>", line 400, in <module>
File "<stdin>", line 221, in app_meta_info
File "<stdin>", line 313, in check_meta_info
File "<stdin>", line 358, in get_file
ImportError: No module named application_mgmt
shell returned 1
可以工作但调用同一个文件类的函数:
def add_meta_info(self, new_application):
new_meta = Application(new_application) # creates obj
saved_meta_info = self.get_file("saved_meta_data")
for metas in saved_meta_info:
if new_meta.name == metas.name:
return False
saved_meta_info.append(new_meta)
self.save_file(saved_meta_info,"saved_meta_data")
del new_meta
文件结构:
.
├── active_screen.glade
├── active_screen.py
├── back
│ ├── application_mgmt.py
│ ├── application_mgmt.pyc
│ ├── bash
│ │ ├── get_active_window.sh
│ │ ├── prosessScript.sh
│ │ └── test_lock.sh
│ ├── bash_schedular.py
│ ├── __init__.py
│ ├── __init__.pyc
│ ├── saved_data
│ │ ├── first_time_builder.py
│ │ ├── saved_active_data
│ │ ├── saved_background_data
│ │ ├── saved_ignore_data
│ │ └── saved_meta_data < HIM
看看错误日志,我不认为你的问题与pickle加载有关。 我不知道他为什么要导入应用程序管理-get_文件的哪一行是第358行?-但恐怖事件可能由以下原因引起:
忘记了上一步文件夹中的\uu init_u文件。没有文件夹就无法导入。如果找不到,创建一个空的。
Python路径问题:要检查这是否是问题所在,请尝试在get_file方法的开头添加此问题。在
import sys sys.path.append('/path/to/the/back/module/')
循环导入:如果发现任何-between应用程序_管理py另一个文件-,尝试重构代码以避免它们。
希望这有帮助。在
相关问题 更多 >
编程相关推荐