From: Alex T. <al...@tw...> - 2004-06-28 00:54:23
|
At 21:36 27/06/2004 -0300, Luis M. Gonzalez wrote: >Hi everyone! > >I have the a problem with the Save file dialog. >What I try to do is serializing a dictionary containing objects with the >Cpickle module. >The name and path of the file should be those entered into the "save file" >dialog, which I created as follows: > >def on_save_mouseClick(self, event): > aStyle = dialog.FILE_SAVE | dialog.FILE_HIDE_READONLY | >dialog.FILE_OVERWRITE_PROMPT > result = dialog.fileDialog(self, 'Save', '', '', "*.data", >aStyle) > myfile= result['paths'] > import cPickle > f = file(myfile, 'w') > cPickle.dump(student.students, f) > f.close() > > >However, when I try to save a file I get is the following error message: >.... >What am I doing wrong? Your problem is that the return from the File dialog is a list of file names (so that the user can select multiple files for input - don't think that applies for a Save dialog - but the result is still a list of file names). >paths > list of strings containing the full pathnames to all files > selected by the user so you need to do maybe myfile - result['paths'][0] or even myfile = result['paths'] if len(myfile) > 0: myfile = myfile[0] -- Alex. |