8st*_*ve8 3 python windows unicode powershell
我想要一个在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 "<stdin>", line 1, in <module>
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 <undefined>
>>>
Run Code Online (Sandbox Code Playgroud)
我使用PowerShell ISE获得了类似的结果,尽管网络上的一些地方声称它支持Unicode或者其他......
Python集成开发环境(IDLE)2.6.2似乎工作正常:
>>> unicode_char=unichr(0xf12)
>>> print unicode_char
?
>>>
Run Code Online (Sandbox Code Playgroud)
IDLE非常慢,我更喜欢另外的shell,任何想法?我可以在PowerShell中完成这项工作吗?
Windows控制台子系统不是Unicode,而是基于代码页.您可以设置代码页:
PS> chcp 65001
PS> ipy64.exe
>>> print unichr(0x3a9)
?
Run Code Online (Sandbox Code Playgroud)
我无法获得(0xF12)给该代码页的正确字符.也许它可以在另一个代码页上找到.
ISE可以显示Unicode并接受Unicode输入,例如,
PS> [char]0xf12
?
PS> [char]0xe4
ä
PS> [char]0x3a9
?
Run Code Online (Sandbox Code Playgroud)
但是,ISE似乎与IronPython解释器不太匹配.
进一步说ISE似乎通过stdout处理来自本机应用程序的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()
?
ä
?
Run Code Online (Sandbox Code Playgroud)