tkFileDialog, askopenfiles in v2.6 question

MRAB google at mrabarnett.plus.com
Wed Nov 26 19:09:33 EST 2008


fransstil wrote:
> To select a group of files works fine in 2.5
> ...
>     from tkFileDialog import askopenfiles
> 
>     fnames = askopenfiles(title = "Select files",
>                           initialdir = "C:\\temp",
>                           filetypes=[("All", "*.*")])
> 
>     for i in range(len(fnames)):
>         fnames[i] = fnames[i].name
>         ...
>     return fnames
> ...
> 
As far as I can see, "tkFileDialog.py" hasn't changed, but it looks like 
one of the modules it uses is 'broken' in some way.

> but now 2.6 strange results
> 
> - IOError: [Errno 2] No such file or directory: u'{'
> 
Internally it's expecting a method to return a list and is then 
iterating through it, but the method is returning a string instead, so 
it's actually iterating through that...

> - ERROR '.name'  no longer exists in 2.6
> 
> - If '.name' removed the return of 'askopenfiles' is no longer a list,
>   it contains braces for some?! of the directories
>   example: {C:/temp/file1.ext} {C:/temp/file2.ext} {C:/temp/file3.ext}
> 
This a what is being returned internally and it should be splitting it 
into a list.

> - askopenfilenames gives the same results
> 
> Can someone gave me a hint
> 
> Thanks in advance
> 
A short-term fix is to use askopenfilenames and split the string 
yourself. It's a space-separated list of paths, each path delimited by 
braces (and a path might contain a space).



More information about the Python-list mailing list