0

我正在尝试使用 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 是否存在一些问题,我应该使用其他东西吗?先感谢您。

4

1 回答 1

0

After a little researching it turns out that the dynamic or relative file paths have trouble being executed while quickly is also being executed. So by switching

  def get_saved_snaps():
try:
    with open('data/newSnapShots.p','rb') as snapFile:

for

def get_saved_snaps():
try:
    with open('/absolute_path/quickly_project/data/newSnapShots.p','rb') as snapFile:

The issue was resolved. I don’t know why relative paths behave this way.

于 2015-04-02T00:22:04.453 回答