Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

To redirect stdin,out

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


thooney at pk

Apr 26, 1999, 8:24 AM

Post #1 of 2 (51 views)
Permalink
To redirect stdin,out

Hello,everyone.

I want to redirect standard input and output
to my C++ stream object and
use something like PyRun_InteractiveLoop().

It seems we can redirect standard output by ...
(quoted from http://www.python.org/doc/FAQ.html)

class StdoutCatcher:
def __init__(self):
self.data = ''
def write(self, stuff):
self.data = self.data +stuff
ToCppObject(self.data) #pass data to
C++ object

import sys
sys.stdout = StdoutCatcher()
print 'foo'

I am at a loss how to redirect standard input.
If you know any solutions,Please Help!


Thanks for reading.

Thooney Millennier


stephan at pcrm

Apr 26, 1999, 11:28 PM

Post #2 of 2 (50 views)
Permalink
To redirect stdin,out [In reply to]

Thooney Millennier <thooney [at] pk> writes:

>
> import sys
> sys.stdout = StdoutCatcher()
> print 'foo'
>
> I am at a loss how to redirect standard input.
> If you know any solutions,Please Help!

Well, I tried the obvious analog of this code snippet:

import sys
sys.stdin = open("one_of_my_files.txt")
print raw_input()

And it seemded to work fine. Am I missing something?

Greetings,

Stephan

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.