1

dill用来将 python 对象存储到一个文件中,例如:

with open(filename, 'wb') as output_:
    dill.dump(obj, output_)

test.dprj然后我从文件 C:...\DyS_project\testsread_write.py加载存储的对象

import pprint
from MBD_system import read_and_write
from MBD_system.MBD_system import MBDsystem

if __name__ == "__main__":
    MBD_file_abs_path = "C:\...\\test.dprj"
    mbd = read.read(MBD_file_abs_path)
    pprint(vars(mbd))

它工作正常并打印对象属性。但是,如果我尝试DySMainWindowC:...\DyS_project\dys.py的应用程序中加载文件

from MBD_system.MBD_system import MBDsystem
from MBD_system import read_and_write

class DySMainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(DySMainWindow, self).__init__()

    def showOpenFileDialog(self):
        ...
        self.MBD_system = None
        self.MBD_system = read_and_write.read(filename)
        print self.MBD_system.__dict__
        pprint(vars(self.MBD_system))

字典打印正确,但是当我pprint(vars())用来打印对象的属性时,它会引发:

File "C:/.../DyS_project/dys.py", line 577, in showOpenFileDialog
pprint(vars(self.MBD_system))
TypeError: 'module' object is not callable

任何想法什么是错的以及如何解决它?

4

1 回答 1

0

我已经解决了实际上是一个糟糕的隐藏类型的问题。我已经更改了代码:

import pprint

至:

from pprint import pprint
于 2016-07-22T13:05:30.343 回答