473,761 Members | 4,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('UT F8')

Now the trouble is I am getting that darn UnicodeDecodeEr ror, 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 3316
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('UT F8')

Now the trouble is I am getting that darn UnicodeDecodeEr ror, 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.getprefe rredencoding()
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.getprefe rredencoding()
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.getprefe rredencoding()
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 Drwald
Jul 18 '05 #8

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

Similar topics

4
4943
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 longer see the Asian fonts, but he could when the pages were on the other server. Can anyone think of why a Windows 2000 user could once see Asian fonts but cannot now? These are the meta tags I used on those pages: <meta...
6
3804
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 one day): \\FFDS24\ASP.NET Applications(_LM_W3SVC_1_Root_ATV2004)\Errors During Execution: 7 \\FFDS24\ASP.NET Apps v1.1.4322(_LM_W3SVC_1_Root_ATV2004)\Compilations
0
1752
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 http://database.sarang.net/?criteria=pgsql becase there is no korean postgresql list. poster is "joesp"
1
1980
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 datatype column. I have found that the XML in SQL stores all data as UTF-16. Does anyone know an easy way to programmatically convert my incoming XML into UTF-16? I have to maintain the foreign characters within the document. I have found that I can...
0
1002
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 I need to change it to UTF-8. I cannot find any place where I can change the default encoding (the Korean just shows up as messed up ascii on the web - changing the view->encoding doesn't work). It's a real pain if I have to resave every file,...
1
2262
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 hard-coded literals. Anyways, can't I set VS.NET 2005 always create and save C# files in UTF-8 encoding? Currently it seems that VS.NET is using ascii encoding. SharpDevelop (C# ide) has this option (Options->Text editor- provides a similar option.
3
2981
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 convert "gibberish" like "¿ï±îºÁ ¿ôÀݾÆ"to it's original form in Korean as "울까봐 웃잖아" (I understand that if you don't have the Korean language pack installed you won't be able to see the original form, sorry). I am not very...
1
4347
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 is working well. When Multibyte characters are involved like Japanese, Chinese or Korean, I need to convert UTF8 to ANSI encoding to get the correct values.
7
2200
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 do an automatic filtering/converting to utf16, or do they do something else? Do they default to utf8 if the xml file does not specify an encoding? Bill
0
9554
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9377
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10136
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9811
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7358
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5266
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3913
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3509
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.