Piping stdout to Python callable
apardon at forel.vub.ac.be
Tue Aug 17 14:05:14 CEST 2004
Op 2004-08-17, Edward Diener schreef <eldiener at earthlink.net>:
> From within a function in my own module I need to take the output from a
> Python module "A", which is sending data to stdout and which can not be
> changed and which I need to invoke as a top-level module, and pipe it into
> another function in my own module so that I can read it from stdin. Is there
> an easy way to do this ? The only way I can presently think to do this is
> through "system python A.py | python MyOwnModule.py", which seems a bit
> laborious having to invoke python.exe itself twice. Any other solution would
> be most welcome.
What do you mean when you say you need to invoke it as a top-level
module? Do you mean you can't import it at all or that importing it will
startup the process of generating output immediatly?
What bothers you with twice invoking the interpreter? In these days
a program that is invoked multiples times will generally be only
loaded once in memory.
Are threads an acceptable alternative? Does your MyOwnModule.py needs
to write to stdout?
More information about the Python-list