我正试图使用python快速构建一个应用程序。大多数情况下,一切都正常。然而,当我试图运行一个读取.p(pickle)文件的函数时,我会遇到I/O错误。奇怪的是,当我在shell中运行同一个python程序时,它运行得很好。
adam@adam-System-Product-Name:~/reskin/reskin$ quickly run
2, No such file or directory, newSnapShots.p
Traceback (most recent call last):
File "bin/reskin", line 36, in <module>
reskin.main()
File "/home/adam/reskin/reskin/__init__.py", line 31, in main
window = ReskinWindow.ReskinWindow()
File "/home/adam/reskin/reskin_lib/Window.py", line 37, in __new__
new_object.finish_initializing(builder)
File "/home/adam/reskin/reskin/ReskinWindow.py", line 36, in finish_initializing
self.set_app_data(builder)
File "/home/adam/reskin/reskin/ReskinWindow.py", line 43, in set_app_data
viewControler.app_by_name("firstVar")
File "/home/adam/reskin/reskin/back/viewControler.py", line 29, in app_by_name
app = applicationGetter.get_app_by_name(name)
File "/home/adam/reskin/reskin/back/applicationGetter.py", line 8, in get_app_by_name
for snap in savedSnaps:
TypeError: 'bool' object is not iterable
打印错误的功能:
def get_saved_snaps():
try:
with open('data/newSnapShots.p','rb') as snapFile:
savedSnaps = pickle.load(snapFile)
except IOError as e:
print "{0}, {1}, newSnapShots.p ".format(e.errno, e.strerror)
return False
return savedSnaps
文件树和.p位置
.
├── applicationGetter.py
├── applicationGetter.pyc
├── data
│ └── newSnapShots.p < file here
├── firstTimeSnapList.py
├── __init__.py
├── __init__.pyc
├── prosessCheckerv3.py
├── prosessScript.sh
├── viewControler.py
└── viewControler.pyc
快速使用Cpickle有问题吗?我应该使用其他东西吗?提前谢谢。
经过一点研究,发现动态或相对文件路径在执行时遇到问题,同时也在快速执行。所以通过切换
def get_saved_snaps():
try:
with open('data/newSnapShots.p','rb') as snapFile:
对于
def get_saved_snaps():
try:
with open('/absolute_path/quickly_project/data/newSnapShots.p','rb') as snapFile:
问题已经解决。我不知道为什么相对路径会这样。