2015-04-01 60 views
0

我想在python中使用快速生成應用程序主要是一切正常但是當我嘗試運行讀取.p(pickle)文件的函數時,我得到一個I/O錯誤。奇怪的是,當我在shell中運行相同的python程序時,它工作正常。快速運行時和.p文件

[email protected]:~/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的使用與迅速,我應該用別的東西來代替一些問題? 預先感謝您。

+0

如果您希望加載可迭代的東西,並且在錯誤情況下想要執行的所有操作都是打印警告,那麼get_saved_snaps錯誤情況下的更好返回值將是可迭代的。 – 2015-04-15 23:19:56

回答

0

經過一番研究發現,動態文件路徑或相對文件路徑在快速執行的同時也遇到了麻煩。因此,通過切換

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: 

的問題就解決了。我不知道爲什麼相對路徑以這種方式表現。