我想要一个在Windows上支持Unicode的 shell 。 PowerShell出厂时似乎没有。
PowerShell V2(Windows 7 x64):PS C:\> powershell
Windows PowerShell
Copyright (C) 2009 Microsoft Corporation. All rights reserved.
PS C:\> python
Python 2.6.2 (r262:71605, Apr 14 2009, 22:46:50) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> unicode_char=unichr(0xf12)
>>> unicode_char
u'\u0f12'
>>> print unicode_char
Traceback (most recent call last):
File "", line 1, in
File "C:\python26\lib\encodings\cp437.py", line 12, in encode
return codecs.charmap_encode(input,errors,encoding_map)
UnicodeEncodeError: 'charmap' codec can't encode character u'\u0f12' in position 0: character maps to
>>>
我在PowerShell ISE上得到了类似的结果,尽管网络上的某些地方声称它支持Unicode或其他任何东西。
Python集成开发环境(IDLE)2.6.2似乎可以正常工作:
>>> unicode_char=unichr(0xf12)
>>> print unicode_char
༒
>>>
空闲很慢,我希望有另一个 shell ,有什么想法吗?我可以在PowerShell中进行这项工作吗?
最佳答案
Windows控制台子系统不是Unicode,而是基于代码页的。您可以尝试设置代码页:PS> chcp 65001
PS> ipy64.exe
>>> print unichr(0x3a9)
Ω
我无法(0xF12)使用该代码页提供正确的字符。也许可以在另一个代码页上找到它。
ISE可以显示Unicode并接受Unicode输入,例如,
PS> [char]0xf12
༒
PS> [char]0xe4
ä
PS> [char]0x3a9
Ω
但是,ISE在IronPython解释器中似乎无法很好地发挥作用。
进一步讲,ISE似乎可以通过stdout处理来自 native 应用程序的Unicode:
$src = @'
namespace Foo {
public class Bar
{
public static void Baz()
{
System.Console.Out.WriteLine("\u0f12");
System.Console.Out.WriteLine("\u00e4");
System.Console.Out.WriteLine("\u03a9");
}
}
}
'@
Add-Type -TypeDefinition $src
[Foo.Bar]::Baz()
༒
ä
Ω