python编码转换powershell,python - 使用Python在PowerShell中使用Unicode? Windows中的替代Shell?...

我想要一个在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()

ä

Ω

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值