我有一个从pickle文件导入数据的应用程序.它适用于Windows,但Mac和Linux的行为很奇怪.
在OS X中,除非我将文件类型设置为*.*,否则pickled文件(文件扩展名".char")不可用作选择.然后,如果我选择一个具有.char扩展名的文件,它将不会加载,从而产生错误
Run Code Online (Sandbox Code Playgroud)unpickle_file = cPickle.load(char_file)ValueError:无法将字符串转换为float
但是,如果我创建一个没有.char扩展名的文件,该文件将加载正常.
在Linux中,当我使用"文件打开"对话框时,我的pickle文件是不可见的,无论它们是否具有文件扩展名.但是,我可以在Nautilus或Dolphin下看到它们.它们根本不存在于我的应用程序中.
编辑这是保存代码:
def createSaveFile(self):
"""Create the data files to be saved and save them.
Creates a tuple comprised of a dictionary of general character information
and the character's skills dictionary."""
if self.file_name:
self.save_data = ({'Name':self.charAttribs.name,
<snip>
self.charAttribs.char_skills_dict)
self.file = open(self.file_name, 'w')
cPickle.dump(self.save_data, self.file)
self.file.close()
Run Code Online (Sandbox Code Playgroud)
这是开放代码:
def getCharFile(self, event): # wxGlade: CharSheet.<event_handler>
"""Retrieve pickled character file from disk."""
wildcard = "Character files (*.char) | *.char | All files (*.*) | *.*"
openDialog …Run Code Online (Sandbox Code Playgroud)