deleting the terminal prompt?

M

MackS

Dear all,

I just noticed the following behavior when I run

import os
import sys
import readline

histfile = os.path.join(os.environ["HOME"], ".pyhist")

try:
readline.read_history_file(histfile)
except IOError:
pass

import atexit
atexit.register(readline.write_history_file, histfile)
del os, histfile

while cmd != "":

sys.stdout.write("prompt: ")
cmd = raw_input()

# at this point it studies the contents of cmd and decides what to
do next.

However, if the user simply presses Tab followed by a backspace s/he
effectively makes the prompt disappear. Is there a way to prevent this
from happening?


Thanks for any help,

Mack
 
D

Dennis Lee Bieber

while cmd != "":

sys.stdout.write("prompt: ")
cmd = raw_input()

# at this point it studies the contents of cmd and decides what to
do next.

However, if the user simply presses Tab followed by a backspace s/he
effectively makes the prompt disappear. Is there a way to prevent this
from happening?
What behavior does...

while cmd != "":
cmd = raw_input("prompt: ")

.... give you?

--
 
D

Dennis Lee Bieber

Thanks, Dennis, that solved it.
Good to know.

I'll confess, I hadn't double-checked the behavior myself -- I
was hoping that the coders of raw_input() were smart enough to ensure
that the prompt string that it takes was refreshed if the user ran
back-spaces/deletes/etc. I jumped on that since it looked like you
hadn't realized it /had/ a prompt argument, and the disjoint write/input
sequence has no common state information.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,239
Messages
2,571,200
Members
47,838
Latest member
elibuskamoSeAve

Latest Threads

Top