469,360 Members | 1,799 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,360 developers. It's quick & easy.

Problem with tkFileDialog.askdirectory(), Windows,and non-ascii paths

I have the current Windows binary install of Python 2.3.4 on my
Windows XP system.

I am pained to discover that tkFileDialog.askdirectory() returns a
mangled path when a directory is selected which has non-ascii Unicode
path, as in Kanji characters, i.e. the usull "????" in place of the
original UTF-8 code points. .

After some time spent Google'ing. I don't find a discussion of this.
Is there some option or configuration change I can make to fix this?
I can roll my own file-dialog , but I prefer to re-use code.
Jul 18 '05 #1
2 3897
Read Roberts <rr******@adobe.com> wrote in message news:<ma**************************************@pyt hon.org>...
I have the current Windows binary install of Python 2.3.4 on my
Windows XP system.

I am pained to discover that tkFileDialog.askdirectory() returns a
mangled path when a directory is selected which has non-ascii Unicode
path, as in Kanji characters, i.e. the usull "????" in place of the
original UTF-8 code points. .

After some time spent Google'ing. I don't find a discussion of this.
Is there some option or configuration change I can make to fix this?
I can roll my own file-dialog , but I prefer to re-use code.


I had a problem with using tkFileDialog.filename between Windows and
Linux. The solution I got was to use unicode().
In article <fa**************************@posting.google.com >,
ti**************@nvl.army.mil (Tim Williams) wrote:

>I'm using Python 2.3.2 and tkFileDialog in a program I have. I'm
>trying to use this on Linux (RH 8.0) and Windows 2000. When I first >upgraded from v2.2 to v2.3. I noticed that
>tkFileDialog.askopenfilename() returns a tuple on Cancel instead of >''. I found that the Windows version still returns a string (''). Now >I'm finding out that tkFileDialog.Directory().show() does this too. ... >How can I check tkFileDialog to do the "right" thing? All I want is >the string that contains the path, but I want this to work on both >Linux and Windows.

Is this the sort of thing you want?

dirobj = tkFileDialog.askdirectory()
if not dirobj:
# user Cancelled; works whether the return is '' or ()
return

# dirobj may be a string or a Tk_Obj
dirname = unicode(dirobj)

The same code should work for askopenfilename.


HTH
Jul 18 '05 #2
Thank your for your response. I did see your
e-mail when googl'ing for similar issues.
However, the problem you had was that the the
object returned on cancelling is different
bertween Linux and Windows.

My problem is that when you do select a directory
with the tkFileDialog.askdirectory() , on
Windows the object returned is a byte string,
with the non-ascii characters converted to '?".
Applying the 'unicode" function to this cannot
restore the lost data.

The particular path i am struggling with a a
parent directory with the utf-8 name:
"\343\201\246\343\201\231\343\201\250\343\203\225\ 343\202\251\343\203\253\343\202\277\343\202\231"
- Read Roberts


At 5:06 AM -0700 10/8/04, Tim Williams wrote:
Read Roberts <rr******@adobe.com> wrote in
message
news:<ma**************************************@py thon.org>...
I have the current Windows binary install of Python 2.3.4 on my
Windows XP system.

I am pained to discover that tkFileDialog.askdirectory() returns a
mangled path when a directory is selected which has non-ascii Unicode
path, as in Kanji characters, i.e. the usull "????" in place of the
original UTF-8 code points. .

After some time spent Google'ing. I don't find a discussion of this.
Is there some option or configuration change I can make to fix this?
I can roll my own file-dialog , but I prefer to re-use code.


I had a problem with using tkFileDialog.filename between Windows and
Linux. The solution I got was to use unicode().
In article <fa**************************@posting.google.com >,
ti**************@nvl.army.mil (Tim Williams) wrote:

>I'm using Python 2.3.2 and tkFileDialog in a program I have. I'm
>trying to use this on Linux (RH 8.0) and Windows 2000. When Ifirst >upgraded from v2.2 to v2.3. I noticed that
>tkFileDialog.askopenfilename() returns a tuple on Cancel insteadof >''. I found that the Windows version still returns a string ('').Now >I'm finding out that tkFileDialog.Directory().show() does thistoo. ... >How can I check tkFileDialog to do the "right" thing? All I wantis >the string that contains the path, but I want this to work onboth >Linux and Windows.

Is this the sort of thing you want?

>>> dirobj = tkFileDialog.askdirectory()
if not dirobj:
# user Cancelled; works whether the return is '' or ()
return

# dirobj may be a string or a Tk_Obj
dirname = unicode(dirobj)
**
The same code should work for askopenfilename.


HTH
--
http://mail.python.org/mailman/listinfo/python-list


Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike Abel | last post: by
2 posts views Thread by Tim Williams | last post: by
2 posts views Thread by Irmen de Jong | last post: by
1 post views Thread by Justin Straube | last post: by
reply views Thread by John Wheez | last post: by
9 posts views Thread by cdroulers | last post: by
1 post views Thread by Gheorghe Postelnicu | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.