[Python-Dev] Incorrect documentation of the raw_input built-in function

Oleg Broytmann phd at phd.pp.ru
Thu Jan 24 18:44:26 CET 2008


On Thu, Jan 24, 2008 at 12:36:51PM -0500, Isaac Morland wrote:
> What about an option (maybe even a default) to send the prompt to stdin?
> 
> The Postgres command line interface psql appears to do this:
> 
> $ psql 2>&1 >/dev/null
> Password:
> $
> 
> (I typed my password and then I quit by typing ^D; if I type the wrong 
> password, it looks the same on screen but it quits right away without 
> waiting for ^D)
> 
> I think ssh also does this when it needs to prompt for a password.

   One cannot write to stdin:

>>> sys.stdin.write("1\n")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IOError: [Errno 9] Bad file descriptor

   But it is possible to explicitly open the current console for reading
and writing and do I/O regardless of stdin/stdout/stderr redirects:

>>> tty = open("/dev/tty", "r+")
>>> tty.write("1\n")
1
>>> line = tty.readline()
DDD
>>> line
'DDD\n'

Oleg.
-- 
     Oleg Broytmann            http://phd.pp.ru/            phd at phd.pp.ru
           Programmers don't die, they just GOSUB without RETURN.


More information about the Python-Dev mailing list