what does "python -i" use as input stream (stdin)?
almar.klein at gmail.com
Wed Oct 1 19:48:52 CEST 2008
I wanted to give your solution a try, but got stuck.
The file that I want to replace the "standard input" with is a pseudo file
object with a custom read method. I have a hard time finding out how
to have a file descriptor (or fileno) associated with it.
I tried inheriting from the "file" class (using a dummy file on disk), and
overriding the read() and __init__() method. To test I used
but it reads the contents of my dummy file rather than using my read method.
So obviously it does some low level stuff there...
Again I have the feeling this is impossible, but I thought that the last
time too :)
2008/9/30 Almar Klein <almar.klein at gmail.com>
> it's that easy...
> 2008/9/29 Gabriel Genellina <gagsl-py2 at yahoo.com.ar>
> En Fri, 26 Sep 2008 04:29:42 -0300, Almar Klein <almar.klein at gmail.com>
>> I would still like to hear if anyone knows how I can change the input
>>> is used when running "python -i", but I would not be surprised if it is
>> Sure you can. You have to replace the file descriptor 0, that is,
>> "standard input"; sys.stdin reads from there. The standard way is to use
>> c:\temp>type foo.txt
>> This line read from foo.txt
>> c:\temp>type redirect.py
>> import os
>> inp = open("foo.txt","r")
>> os.dup2(inp.fileno(), 0)
>> print "raw_input->", raw_input()
>> c:\temp>python redirect.py
>> raw_input-> This line read from foo.txt
>> This is not
>> Gabriel Genellina
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-list