Can't type the "b" letter in Python shell in OS X

I have a problem with my "b" letter in Python shell in OS X. I can't type "b", but "B" worked fine.

How can I solve this issue?


Solution 1:

The problematic line in your .pythonstartup is something like:

 readline.parse_and_bind("bind ^I rl_complete") # darwin libedit

This .pythonstartup will fix it...

try:
    import readline
except ImportError:
    print "Module readline not available."
else:
    import rlcompleter
    if 'libedit' in readline.__doc__:
        readline.parse_and_bind("bind ^I rl_complete")
    else:
        readline.parse_and_bind("tab: complete")

Solution 2:

First, this did not happen until I updated python 2.7.1 to 2.7.3. That said, the fix is on the line:

old line:

if(sys.platform == 'darwin'): #FIX

new line:

if(sys.platform == 'darwin') and 'libedit' in readline.__doc__: #FIX

The full code in my ~/.pythonrc

import atexit
import os
try:
    import readline
except ImportError:
    print "Module readline not available."
else:
    import rlcompleter
    import sys
    if(sys.platform == 'darwin') and 'libedit' in readline.__doc__: #FIX
    # OSX
        readline.parse_and_bind ("bind ^I rl_complete")
    else:
    # Linux
        readline.parse_and_bind("tab: complete")

historyPath = os.path.expanduser("~/.pyhistory")

def save_history(historyPath=historyPath):
    readline.write_history_file(historyPath)

if os.path.exists(historyPath):
    readline.read_history_file(historyPath)

atexit.register(save_history)
del atexit, save_history, historyPath