473,387 Members | 1,364 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 4233
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Tim Williams | last post by:
I just installed Python 2.3 on my Redhat system. When I tried to run one of my programs that use tkFileDialog.askopenfilename(), I got an error because it returns a tuple instead of a null string...
1
by: Mike Abel | last post by:
Hello i have a Linux Mandrake Distribution with Python 2.3 and Tcl/Tk 8.4. Python 2.2 and Tcl/Tk 8.3.3 returns an String if i made this: x = tkFileDialog.askdirectory(initialdir="was auch...
3
by: Tim Williams | last post by:
Hi. I'm using Python 2.3 and trying to use tkFileDialog to get a list of files. I get a message about the '-multiple' option is not a valid option in the call to Open. Python 2.3 (#1, Aug ...
2
by: Tim Williams | last post by:
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...
2
by: Irmen de Jong | last post by:
Hi, I'm having trouble with the code below. It's just a regular Tk text widget in which you can type and select text as expected, however the call to tkFileDialog.askopenfilename() seems to screw...
1
by: Justin Straube | last post by:
Hopefully someone can catch what im missing here. Ive googled this and I think Ive got the filetypes arg written properly, but I get a traceback when calling this function. Heres the code...
0
by: John Wheez | last post by:
Hi all, I'm using teh tkFileDialog to let teh user select a directory. We have long names which make it difficult to view the directories. For some reason the GUI windows doesn;t expand on...
9
by: cdroulers | last post by:
Hello, I am working on a school project that requires me to get the path of a filename for future treatment. I've tried getting a file with tkFileDialog.askopenfile. ...
1
by: Gheorghe Postelnicu | last post by:
In our example, try replacing the last line with print file.name ---------- Forwarded message ---------- From: cdroulers@hotmail.com To: python-list@python.org Date: 8 Nov 2006 11:01:08...
2
by: Traclo | last post by:
Hello all! I have a problem concerning tkFileDialog. When I use the the askopenfilename command to open a text file it opens a tkinter window (apart from the file browsing window) which refuses to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.