Delete key in System Python

Hi all,

I have removed a MacPython installation and returned to the /System python for Leopard. My Terminal works fine, and if I push delete key it just deletes to the right, as it should do. The problem is that inside python I get a '~' character instead of deleting.
Any ideas on what may be causing this?

Thanks,
Albert

MacBook (White) CoreDuo 2, Mac OS X (10.5.8)

Posted on Feb 24, 2010 12:24 PM

Reply
11 replies

Feb 24, 2010 1:33 PM in response to DjKarras

What happens if you use Control-H ?

There is an Terminal -> Preferences -> Advanced -> Delete sends Ctrl-H

I'm not sure if this will work well with every thing you use with your Terminal, so use with caution.

I am NOT a Python person, so I'm guessing here. Maybe the terminfo profile for your TERM environment setting does not properly tell Python what the Delete character is.

Next idea is the 'stty' settings

stty -a

My Terminal says

erase = ^?

is the erase character, where ^? is what I always see for the delete key on just about every Unix system I've used in the last 15 years.

NOTE: I did enter Python

python

and was able to delete stuff I had typed. It worked as I would expect.

My TERM environment variable is xterm-16color. I also tried xterm-color, xterm, vt100, and then I stopped.

Feb 24, 2010 7:47 PM in response to DjKarras

When you switched the Terminal preference from Delete is Control-H to unchecked, did you try creating a new Terminal session? Or even quitting and restarting Terminal? Sometimes preferences such as this affect the Next Terminal session. Just want to turn over every possible "Rock".

My python is the Mac OS X 10.5.8 version

/usr/bin/python

My locale is I assume the default for American English. The locale command says says

locale
LANG=
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

I DO NOT have a .inputrc (no readline customization).

My keyboard is the MacBook keyboard.

Just checking if you are getting 0x7F as the delete key. This is a situation where to only way out is to close the Terminal Window or Tab.

stty raw; hexdump

now just keep hitting the Delete key until you get a line of output (16 Deletes should do it):

0000000 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f 7f

But because you put your session into Raw mode, you can not kill the hexdump command. So the only way out is to just close the Terminal session (Command-W), or Quit Terminal.

If you can think of any other variables we could check, I'll be glad to provide what I can.

Or maybe someone else will just provide a solution 🙂

Message was edited by: BobHarris

Feb 25, 2010 1:51 AM in response to BobHarris

So, my python is the same, but could you check where it points to?

albert@dc10:~$ which python
/usr/bin/python
albert@dc10:~$ ls -l /usr/bin/python
lrwxr-xr-x 1 root wheel 72B 5 oct 22:33 /usr/bin/python -> ../../System/Library/Frameworks/Python.framework/Versions/2.5/bin/python


On the other side, my locale is the default Spanish one:

LANG="es_ES.UTF-8"
LCCOLLATE="esES.UTF-8"
LCCTYPE="esES.UTF-8"
LCMESSAGES="esES.UTF-8"
LCMONETARY="esES.UTF-8"
LCNUMERIC="esES.UTF-8"
LCTIME="esES.UTF-8"
LC_ALL=


and hexdump is a little bit strange. On my Macbook, I need to press Fn+Backspace to get the Forward delete, and this is what I get from hexdump

albert@dc10:~$ stty raw; hexdump
0000000 1b 5b 33 7e 1b 5b 33 7e 1b 5b 33 7e 1b 5b 33 7e


Strange...

Message was edited by: DjKarras

Feb 25, 2010 2:35 AM in response to DjKarras

The /Systrem Python (/usr/bin/python) does not use GNU readline. Its command line editing is quite primitive, and I guess it does not have the "delete to the right" function.

If you really need "delete to the right", then you can emulate it by
"cursor right" + "backspace".

Go to Terminal > Preferences > Settings > Keyboad,
select "forward delete" from the list,
push the Edit button (or double click the Action field),
select "send string to shell:" , and type
"ESC" "[" "C" "ctrl-H" (four key strokes), or
"right-arrow" "ctrl-H" (two key storkes). The tex box should look like

[C

Then push the OK button.

Now hitting the "forward delete" key in the Python interpreter will "delete to the right" unless the cursor is already at the end of the line, in which case it acts as "backspace".
But this setting may break the behavior of the "forward delete" key in other software, such as vi editor.

I have removed a MacPython installation


Are there anything wrong with MacPython?

Feb 25, 2010 6:18 AM in response to Jun T.

{quote:title=Jun T. wrote:}> Are there anything wrong with MacPython?{quote}

I had a problem with the ROOT software, it didn't work, and in fact my site-packages were going crazy: sometimes to /System, sometimes to /Library/Frameworks sometimes to /Library/Python... I would like very much to have MacPython installed but I don't know how ti keep the site-packages under control, as if the system python didn't exist. Any help with that?

Thanks a lot,
Albert

Feb 25, 2010 7:47 AM in response to DjKarras

Unless you expricitly specify PYTHONPATH, Apple's python (/usr/bin/python) uses only
/System/Library/Frameworks/Python.framework/ and
/Library/Python/2.x/site-packages/,
while MacPython (/usr/local/bin/python) uses only
/Library/Frameworks/Python.framework/,
and they should not interfare, in theory.

If you are using Apple's python, and if you have installed newer versions of pre-installed packages (such as numpy) into /Library/Python/2.x/site-packages/, then you should
export PYTHONPATH=/Library/Python/2.5/site-packages:$PYTHONPATH
so that the newer version is used instead of the version pre-installed by Apple.
Of course if you are using MacPython then never include /Library/Python/2.5/site-packages in PYTHONPATH.

I have never used PyROOT, so I don't know whether it works with Apple's python orr not. Did you ask in PyROOT comunity?

By the way, if you want to use IDLE with Apple's python, then just type
/usr/bin/python -m idlelib.idle
to your shell prompt. It has much better command line editing support.

Feb 26, 2010 12:43 AM in response to DjKarras

but now I cannot write the letter 'b'

I can't understand what your problem is.
Which version of MacPython are you using? Where did you get it from?

Anyway, if your objective is to use PyROOT, then you must first make it clear whether PyROOT can be
installed for Apple's Python or not. Install MacPython only if you really need it.

If your objective is to have better command line editing in python interpreter, then try IDLE as
suggested in my previous post. You don't need MacPython to use IDLE.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Delete key in System Python

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.