473,407 Members | 2,314 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,407 software developers and data experts.

How to print this character u'\u20ac' to DOS terminal

Who could explain the follow issue ?
>>print u'Δ'
Δ
>>print u''
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'gbk' codec can't encode character u'\x80' in
position 0: il
legal multibyte sequence
>>>
or I just put the unicode number
>>print u'\u0394'
Δ
>>print u'\u20ac'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in
position 0:
illegal multibyte sequence
>>>
My terminal is cmd.exe under windows XP.
what's the different between the two character ? what can I do if I
want to print the u'\u20ac'?

May 30 '07 #1
7 5676
人言落日是天涯,望极天涯不见家 schrieb:
Who could explain the follow issue ?
>>>print u'\u0394'
Δ
>>>print u'\u20ac'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in
position 0:
illegal multibyte sequence

My terminal is cmd.exe under windows XP.
what's the different between the two character ? what can I do if I
want to print the u'\u20ac'?
The problem is that your terminal uses (some form of) the GBK encoding;
see http://zh.wikipedia.org/wiki/GBK for details on GBK.

It seems that GBK (or, rather, code page 936) supports the delta
character, but not the euro sign.

To change that, you can use "chcp" in your terminal window.
For example, if you do "chcp 850", you should be able to
display the euro sign (but will simultaneously use the ability
to display the letter delta, and the chinese letters).

I don't know whether the terminal supports an UTF-8 code
page; you can try setting the terminal's code page to
65001 (which should be UTF-8).

Regards,
Martin
May 30 '07 #2
On 5月30日, 下午1时23分, "Martin v. Lo"wis" <mar...@v.loewis.dewrote:
人言落日是天涯,望极天涯不见家 schrieb:
Who could explain the follow issue ?
>>print u'\u0394'
Δ
>>print u'\u20ac'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in
position 0:
illegal multibyte sequence
My terminal is cmd.exe under windows XP.
what's the different between the two character ? what can I do if I
want to print the u'\u20ac'?

The problem is that your terminal uses (some form of) the GBK encoding;
seehttp://zh.wikipedia.org/wiki/GBKfor details on GBK.

It seems that GBK (or, rather, code page 936) supports the delta
character, but not the euro sign.

To change that, you can use "chcp" in your terminal window.
For example, if you do "chcp 850", you should be able to
display the euro sign (but will simultaneously use the ability
to display the letter delta, and the chinese letters).

I don't know whether the terminal supports an UTF-8 code
page; you can try setting the terminal's code page to
65001 (which should be UTF-8).

Regards,
Martin
Thanks, but it seems not work yet.

----------------------------------------------------
C:\WINDOWS>chcp 850
Active code page: 850

C:\WINDOWS>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>print u'\u20ac'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python25\lib\encodings\cp850.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac'
in position
0: character maps to <undefined>
C:\WINDOWS>chcp 65001
Active code page: 65001

C:\WINDOWS>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>print u'\u20ac'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
LookupError: unknown encoding: cp65001
-----------------------------------------------
I find that the u'\u20ac' related 'mbcs' encode is 0x80, I could print
it directly
>>print '\x80'
>>>
But the string contained the u'\u20ac' is get from remote host. Is
there any method to decode it to the local 'mbcs'?

May 30 '07 #3
On May 30, 3:05 pm, 人言落日是天涯,望极天涯不见家 <kelvin....@gmail.comwrote:
On 5月30日, 下午1时23分, "Martin v. Lo"wis" <mar....@v.loewis.dewrote:
人言落日是天涯,望极天涯不见家 schrieb:
Who could explain the follow issue ?
>>>print u'\u0394'
Δ
>>>print u'\u20ac'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in
position 0:
illegal multibyte sequence
My terminal is cmd.exe under windows XP.
what's the different between the two character ? what can I do if I
want to print the u'\u20ac'?
The problem is that your terminal uses (some form of) the GBK encoding;
seehttp://zh.wikipedia.org/wiki/GBKfordetails on GBK.
It seems that GBK (or, rather, code page 936) supports the delta
character, but not the euro sign.
To change that, you can use "chcp" in your terminal window.
For example, if you do "chcp 850", you should be able to
display the euro sign (but will simultaneously use the ability
to display the letter delta, and the chinese letters).
I don't know whether the terminal supports an UTF-8 code
page; you can try setting the terminal's code page to
65001 (which should be UTF-8).
Regards,
Martin

Thanks, but it seems not work yet.

----------------------------------------------------
C:\WINDOWS>chcp 850
Active code page: 850

C:\WINDOWS>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.>>>print u'\u20ac'

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python25\lib\encodings\cp850.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac'
in position
0: character maps to <undefined>

C:\WINDOWS>chcp 65001
Active code page: 65001

C:\WINDOWS>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.>>>print u'\u20ac'

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
LookupError: unknown encoding: cp65001
-----------------------------------------------
I find that the u'\u20ac' related 'mbcs' encode is 0x80, I could print
it directly
>print '\x80'


But the string contained the u'\u20ac' is get from remote host. Is
there any method to decode it to the local 'mbcs'?
May 30 '07 #4
On May 30, 3:05 pm, 人言落日是天涯,望极天涯不见家 <kelvin....@gmail.comwrote:
On 5月30日, 下午1时23分, "Martin v. Lo"wis" <mar....@v.loewis.dewrote:
人言落日是天涯,望极天涯不见家 schrieb:
Who could explain the follow issue ?
>>>print u'\u0394'
Δ
>>>print u'\u20ac'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'gbk' codec can't encode character u'\u20ac' in
position 0:
illegal multibyte sequence
My terminal is cmd.exe under windows XP.
what's the different between the two character ? what can I do if I
want to print the u'\u20ac'?
The problem is that your terminal uses (some form of) the GBK encoding;
seehttp://zh.wikipedia.org/wiki/GBKfordetails on GBK.
It seems that GBK (or, rather, code page 936) supports the delta
character, but not the euro sign.
To change that, you can use "chcp" in your terminal window.
For example, if you do "chcp 850", you should be able to
display the euro sign (but will simultaneously use the ability
to display the letter delta, and the chinese letters).
I don't know whether the terminal supports an UTF-8 code
page; you can try setting the terminal's code page to
65001 (which should be UTF-8).
Regards,
Martin

Thanks, but it seems not work yet.

----------------------------------------------------
C:\WINDOWS>chcp 850
Active code page: 850

C:\WINDOWS>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.>>>print u'\u20ac'

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python25\lib\encodings\cp850.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u20ac'
in position
0: character maps to <undefined>

C:\WINDOWS>chcp 65001
Active code page: 65001

C:\WINDOWS>python
Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.>>>print u'\u20ac'

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
LookupError: unknown encoding: cp65001
-----------------------------------------------
I find that the u'\u20ac' related 'mbcs' encode is 0x80, I could print
it directly
>print '\x80'


But the string contained the u'\u20ac' is get from remote host. Is
there any method to decode it to the local 'mbcs'?
forgot to unicode(string) before send it?

May 30 '07 #5
??????????????? wrote:
But the string contained the u'\u20ac' is get from remote host. Is
there any method to decode it to the local 'mbcs'?
remote_string = u'\u20ac'
try:
local_string = remote_string.encode('mbcs')
except:
# no mbcs equivalent available
print "encoding error"
else:
# local_string is now an 8-bit string
print "result:", local_string
# if console is not mbcs, you should see incorrect result
assert result == '\x80'

Mbcs is windows-only so I couldn't test this.

If your application handles text, it may be easier to just leave everything
in Unicode and encode to utf-8 for storage?

Regards,
Tijs
May 30 '07 #6
On 5月30日, 下午9时03分, Tijs <tijs_n...@artsoftonline.comwrote:
??????????????? wrote:
But the string contained the u'\u20ac' is get from remote host. Is
there any method to decode it to the local 'mbcs'?

remote_string = u'\u20ac'
try:
local_string = remote_string.encode('mbcs')
except:
# no mbcs equivalent available
print "encoding error"
else:
# local_string is now an 8-bit string
print "result:", local_string
# if console is not mbcs, you should see incorrect result
assert result == '\x80'

Mbcs is windows-only so I couldn't test this.

If your application handles text, it may be easier to just leave everything
in Unicode and encode to utf-8 for storage?

Regards,
Tijs
Yes, it works, thank you.
But I doubt this way may not work on linux. Maybe I should write some
additional code for supporting both windows and linux OS.

May 30 '07 #7
浜鸿█钀芥棩鏄ぉ娑紝鏈涙瀬澶╂动涓嶈瀹 wrote:

Yes, it works, thank you.
But I doubt this way may not work on linux. Maybe I should write some
additional code for supporting both windows and linux OS.
Depends on what you want to do. Printing to a DOS terminal is hard in
Linux :-) If you write server code, best to keep all text in unicode.

--

Regards,
Tijs
May 30 '07 #8

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

Similar topics

4
by: Joerg Lehmann | last post by:
I am using Python 2.2.3 (Fedora Core 1). The problem is, that strings containing umlauts do not work as I would expect. Here is my example: >>> a = '漩' >>> b = '123' >>> print "%-5s...
4
by: Ricardo Bugalho | last post by:
Hello, I'm using Python 2.3.4 and I noticed that, when stdout is a terminal, the 'print' statement converts Unicode strings into the encoding defined by the locales instead of the one returned by...
3
by: Anthony Liu | last post by:
We know that if we do print '\a' the bell will sound. Now, why do I hear the sound on my local machine when I run a python script on a remote host? I understand if I hear it when I do
5
by: sam | last post by:
hi all, i continue to footle around on my spanking new ultra 20 (1.8GHz / Opteron Model 144), gradually trying to get to grips with python and unix both. the slow print time in IDLE had...
8
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z | last post by:
I lookup the utf-8 form of delta from the link. http://www.fileformat.info/info/unicode/char/0394/index.htm and then I want to print it in the python ( I work under windows) #!/usr/bin/python...
15
by: vinay.khankari | last post by:
How to Print the complete source program as output of the program?
13
by: ramif | last post by:
Is there a way to print extended ASCII in C?? I tried to code something, but it only displays strange symbols. here is my code: main() { char chr = 177; //stores the extended ASCII...
14
by: Ioannis Vranos | last post by:
The following code does not work as expected: #include <wchar.h> #include <locale.h> #include <stdio.h> #include <stddef.h> int main() {
21
by: arnuld | last post by:
I have created a program to print the input words on stdout. Input is taken dynamically from stdin. In each word, each input character is allocated dynamically. I have ran this program with a file...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project梡lanning, coding, testing,...
0
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...

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.