473,386 Members | 1,908 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,386 software developers and data experts.

Trouble with the encoding of os.getcwd() in Korean Windows

Hello All,

I have found much help in the google archives but I am still stuck...

here is my code snippet:
path = os.getcwd()
path = path.decode('UTF8')

Now the trouble is I am getting that darn UnicodeDecodeError, where it
is tripping up on the Korean hangul for My Desktop. Now I have tried
utf8 and utf16 and neither of these works.

So is this my question?: What encoding does windows use for Korean
Windows? I thought it might be and so I surfed around
(http://foundationstone.com.au/HtmlSu...Encodings.html)
and there appears to be an encoding called: windows-949 labeled to be
Korean Windows, which of couse is *not* one of the encodings to be
found in the encodings package... which would suck.

But then I thought about it some more, how could you make software to
do things like read the current directory work on different language
machines??? It would be madness to have a try statement for each and
every encoding under the sun...

Why isn't there a get system encoding method?

Or am I on the entirely wrong track?

Thanks,
-Erik

Jul 18 '05 #1
7 3289
Hello All,

Well as usual, after I post I keep on digging and I found the answer...

http://cjkpython.i18n.org/

Has the encodings for Chinese, Korean and Japanese... and I took the
hint that I found from the foundationstore and tried cp949 and wa-la!
it works...

Now, the question remains, how do I write windows python code that will
work on all flavors of windows languages? The wxPython demo works,
because I have installed it on a path on my machine that does not have
Hangul in the path. But if I distribute something to end users, they
most certainly have Hangul in their path, or Japanese or Chinese, or
some other encoding... so how do you get the correct encoding from the
system?

Thanks,
-Erik

Jul 18 '05 #2
Erik Bethke wrote:
Hello All,

I have found much help in the google archives but I am still stuck...

here is my code snippet:
path = os.getcwd()
path = path.decode('UTF8')

Now the trouble is I am getting that darn UnicodeDecodeError, where it
is tripping up on the Korean hangul for My Desktop. Now I have tried
utf8 and utf16 and neither of these works.

So is this my question?: What encoding does windows use for Korean
Windows?
Try "mbcs". This is a built-in encoding avalaible only on Windows and
that equals the system's default ANSI codepage. Using "mbcs", which is
short for "multi-byte character set", the conversions to and from
Unicode (decode/encode) are internally handled by the corresponding
win32 api functions.

--
Vincent Wehren

I thought it might be and so I surfed around (http://foundationstone.com.au/HtmlSu...Encodings.html)
and there appears to be an encoding called: windows-949 labeled to be
Korean Windows, which of couse is *not* one of the encodings to be
found in the encodings package... which would suck.

But then I thought about it some more, how could you make software to
do things like read the current directory work on different language
machines??? It would be madness to have a try statement for each and
every encoding under the sun...

Why isn't there a get system encoding method?

Or am I on the entirely wrong track?

Thanks,
-Erik

Jul 18 '05 #3
Thank you Vincent, I will try this...

I did get over my troubles with this new code snippet:

encoding = locale.getpreferredencoding()
htmlpath = os.getcwd()
htmlpath = htmlpath.decode( encoding )
That seems to be working well too. I can write to these files and I
can open them with the file dialog, but this is now failing with the
famous aschii error:

webbrowser.open( htmlpath, True, True )

Jul 18 '05 #4
Hello All,

sorry for all the posts... I am *almost* there now...

okay I have this code:

import sys, os

encoding = locale.getpreferredencoding()
htmlpath = os.getcwd()
htmlpath = htmlpath.decode( encoding )

..... write to the file .....
...... file is written fine, and can be opened by both FireFox and IE
and displays fine ...

webbrowser.open( htmlpath.encode ( encoding ), True, True )

the line above now works fine (fixed the ascii error)

but *NOW* my problem is that FirefOX pops up a message box
complaining that the file does not exist, but it certainly does, it
just doesn't like what it is called...

Any ideas now?

Thanks,
-Erik

Jul 18 '05 #5
Ah and PS, again this is only for paths that are non-aschii or at least
have Korean in them...

The broswer bit launches successfully in other locations.

-Erik

Jul 18 '05 #6
Wow, even more information. When I set my default browser to IE, it
launches fine... so it is something about FireFox being more picky than
IE...

Where would I hunt down this sort of problem? Sounds rare, should I
contact Mozilla, or can you guys spot something silly I am doing?

Thank you,
-Erik

Jul 18 '05 #7
Erik Bethke wrote:
Hello All,

sorry for all the posts... I am *almost* there now...

okay I have this code:

import sys, os

encoding = locale.getpreferredencoding()
htmlpath = os.getcwd()
htmlpath = htmlpath.decode( encoding )


You might want to try os.getcwdu() instead of this. According to
http://www.python.org/doc/2.4/lib/os-file-dir.html
this has been added in Python 2.3 and should work on Windows.

Bye,
Walter Dörwald
Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Leora Wenger | last post by:
We moved some pages of Japanese, Korean and Chinese from one server to another. In doing so, the users with Windows XP could still see the Asian fonts. However, a user with Windows 2000 could no...
6
by: Daniel Walzenbach | last post by:
Hi, I have a web application which sometimes throws an “out of memory†exception. To get an idea what happens I traced some values using performance monitor and got the following values (for...
0
by: joseph speigle | last post by:
hi, To see the query results in native language see http://database.sarang.net/?inc=read&aid=5368&criteria=pgsql&subcrit=qna&id=&limit=20&keyword=&page=1 the simpler url is ...
1
by: Matt | last post by:
I have a situation where I am receiving an XML document from a Korean client. They have encoding="EUC-KR" in the XML declaration. This XML file will be placed into a SQL 2005 table with an XML...
0
by: Ben | last post by:
I have an aspx page without anything special on it - just some English and Korean mixed text. My current advanced save encoding is set to Korean Codepage 949 (I don't know how it became that) and...
1
by: Sin Jeong-hun | last post by:
Even though I don't use Korean in my codes and comments, I often need to insert Korean literals, because the target users are Koreans. Because I have no plan to globalize those programs, I use...
3
by: joechu | last post by:
Hello everyone, I am familiar with C, C++ and Java and just started diving into C# .NET but ran into a recent snag. I have been trying to add a function to a custom mp3 tag editor that can...
1
by: Tejas | last post by:
Hi, I am using ldap_get_values() call to get the user attributes from LDAP. This call is returning the user attributes in UTF-8 encoding and its a PCHAR*. For normal English characters this...
7
by: billsahiker | last post by:
if an xml file specifies an encoding, e.g., utf16, do xml browsers and xml editors read and verify each character in the file to make sure it is utf16? and throw an error if it is not, or. do they...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.