bash 如何在 Mac OS X 上的 Python 交互式 shell 中输入英镑字符 (£)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/167439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I enter a pound sterling character (£) into the Python interactive shell on Mac OS X?
提问by Paul D. Waite
Update:Thanks for the suggestions guys. After further research, I've reformulated the question here: Python/editline on OS X: £ sign seems to be bound to ed-prev-word
更新:感谢您的建议。经过进一步研究,我在这里重新表述了这个问题:OS X 上的 Python/editline: £ 符号似乎绑定到 ed-prev-word
On Mac OS X I can't enter a pound sterling sign (£) into the Python interactive shell.
在 Mac OS XI 上,无法在 Python 交互式 shell 中输入英镑符号 (£)。
- Mac OS X 10.5.5
- Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17)
- European keyboard (£ is shift-3)
- Mac OS X 10.5.5
- Python 2.5.1(r251:54863,2008 年 1 月 17 日,19:35:17)
- 欧式键盘(£ 是 shift-3)
When I type “£” (i.e. press shift-3) at an empty Python shell, nothing appears.
当我在一个空的 Python shell 中输入“£”(即按 shift-3)时,什么也没有出现。
If I've already typed some characters, e.g.
如果我已经输入了一些字符,例如
>>> 1234567890 1234567890 1234567890
... then pressing shift-3 will make the cursor position itself after the most recent space, or the start of the line if there are no spaces left between the cursor and the start of the line.
...然后按 shift-3 将使光标定位在最近的空格之后,或者如果光标和行首之间没有空格,则位于行首。
In a normal bash shell, pressing shift-3 types a “£” as expected.
在普通的 bash shell 中,按 shift-3 会按预期键入“£”。
Any idea how I can type a literal “£” in the Python interactive shell?
知道如何在 Python 交互式 shell 中输入文字“£”吗?
采纳答案by Ryan
I'd imagine that the terminal emulator is eating the keystroke as a control code. Maybe see if it has a config file you can mess around with?
我想终端模拟器将击键作为控制代码。也许看看它是否有一个你可以乱搞的配置文件?
回答by Patrick McElhaney
Not the best solution, but you could type:
不是最好的解决方案,但您可以输入:
pound = u'\u00A3'
Then you have it in a variable you can use in the rest of your session.
然后您将它放在一个变量中,您可以在会话的其余部分使用它。
回答by wusher
In unicode it is 00A003. With the Unicode escape it would be u'\u00a003'.
在 unicode 中它是 00A003。使用 Unicode 转义,它将是 u'\u00a003'。
Edit: @ Patrick McElhaney said you might need to use 00A3.
编辑:@ Patrick McElhaney 说您可能需要使用 00A3。
回答by indentation
u'\N{pound sign}'
u'\N{pound sign}'
If you are using ipython, put
如果您使用的是 ipython,请将
execute pound = u'\N{pound sign}'
execute pound = u'\N{pound sign}'
in your ipythonrc file (in "Section: Python code to execute") this way you will always have "pound" defined as the pound symbol in the interactive shell.
在您的 ipythonrc 文件中(在“部分:要执行的 Python 代码”中),您将始终将“磅”定义为交互式 shell 中的磅符号。
回答by Fire Lancer
Must be your setup, I can use the £ (Also european keyboard) under IDLE or the python command line just fine. (python 2.5).
必须是你的设置,我可以在 IDLE 或 python 命令行下使用 £(也是欧洲键盘)就好了。(蟒蛇2.5)。
edit: I'm using windows, so mayby its a problem with the how python works under the mac OS?
编辑:我使用的是windows,所以可能是python在mac OS下的工作方式有问题?

