Tôi có một ứng dụng nhập dữ liệu từ một tệp được nén. Nó hoạt động tốt trong Windows nhưng hành vi của Mac và Linux là lạ.Tệp đã được tải xuống sẽ không tải trên Mac/Linux
Trong OS X, tệp được nhúng (đuôi tệp ".char") không khả dụng dưới dạng lựa chọn trừ khi tôi đặt loại tệp thành *. *. Sau đó, nếu tôi chọn tệp có phần mở rộng .char, nó sẽ không tải, đưa ra lỗi
unpickle_file = cPickle.load(char_file)
ValueError: could not convert string to float
Tuy nhiên, nếu tôi tạo tệp không có đuôi .char, tệp đó sẽ tải lên tốt.
Trong Linux, khi tôi sử dụng hộp thoại "mở tệp", các tệp đã được chọn của tôi không hiển thị, cho dù chúng có mở rộng tệp hay không. Tuy nhiên, tôi có thể nhìn thấy chúng dưới Nautilus hoặc Dolphin. Họ chỉ đơn giản là không tồn tại cho ứng dụng của tôi mặc dù.
Sửa Dưới đây là mã tiết kiệm:
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()
Dưới đây là mã mở:
def getCharFile(self, event): # wxGlade: CharSheet.<event_handler>
"""Retrieve pickled character file from disk."""
wildcard = "Character files (*.char) | *.char | All files (*.*) | *.*"
openDialog = wx.FileDialog(None, "Choose a character file", os.getcwd(),
"", wildcard, wx.OPEN | wx.CHANGE_DIR)
if openDialog.ShowModal() == wx.ID_OK:
self.path = openDialog.GetPath()
try:
char_file = open(self.path, "r")
unpickle_file = cPickle.load(char_file)
char_data, char_skills = unpickle_file
self.displayCharacter(char_data, char_skills)
except IOError:
self.importError = wx.MessageDialog(self,
"The character file is not available!",
"Character Import Error", wx.OK | wx.ICON_ERROR)
self.importError.ShowModal()
self.importError.Destroy()
openDialog.Destroy()
một "tập ngâm" là gì? –
Một tệp được tạo bằng mô-đun dưa (http://docs.python.org/library/pickle.html#module-pickle), một mô-đun được sử dụng để tuần tự hóa và deserialize cấu trúc dữ liệu. –