[Python-Dev] Save file by using file() function and fileDialog()

Amaury Forgeot d'Arc amauryfa at gmail.com
Thu Oct 30 10:02:50 CET 2008


Hello,

On Thu, Oct 30, 2008 at 07:35, Sonia <sonia_16 at live.com> wrote:
>
> I m using fileDialog(self, message, path, filename, filter,
> aStyle(opotional)) to save the file.
> In my code, i used fileDialog to show save dialog box and when we click on
> save button, it should save that file which is of txt type (filter =
> '*.txt'). But when we click on save button it returns error: "coercing to
> unicode: need string or buffer, list found" rather than saving / creating a
> file. I also tried f = file(myfile, 'w', 1000) instead of f = file(myfile,
> 'w'), where 1000 is buffer size, but both have the same error. where as if
> we use
> file( filename[, mode[, bufsize]])
> , then it creates a file of specified type. But it is not working in
> fileDialog(). Why?Where i m wrong?
>
> What should i do?
>
> Following is my code:
> def on_btn2_mouseClick(self, event):
>         aStyle = wx.SAVE|wx.HIDE_READONLY|wx.OVERWRITE_PROMPT
>         filter = '*.txt'
>         result = dialog.fileDialog(self, 'ist def', '', 'n', wildcard,
> aStyle)
>         myfile= result.paths
>         if result.accepted == True :
>             f = file(myfile, 'w')
>             f.write('my file')
>             f.close()

The python-dev mailing list is about the development of Python, not
the development with Python.

Please send this kind of questions to the comp.lang.python newsgroup,
or the wxPython-users mailing list.
There are many python users there willing to help.

Furthermore wxPython is not developed here (or is it PythonCard?), so
you'll get little expertise from us.

(a hint however: "result.paths" likely returns a list of paths; try
"result.paths[0]" to get a file name)
-- 
Amaury Forgeot d'Arc


More information about the Python-Dev mailing list