Line-by-line processing when stdin is not a tty
RG
rNOSPAMon at flownet.com
Wed Aug 11 17:07:27 EDT 2010
In article <rNOSPAMon-3CC595.13205911082010 at news.albasani.net>,
RG <rNOSPAMon at flownet.com> wrote:
> In article <i3uu74$uga$1 at speranza.aioe.org>,
> Tim Harig <usernet at ilthio.net> wrote:
>
> > On 2010-08-11, RG <rNOSPAMon at flownet.com> wrote:
> > > In article <i3uo7t$6mk$1 at speranza.aioe.org>,
> > > Tim Harig <usernet at ilthio.net> wrote:
> > >
> > >> On 2010-08-11, RG <rNOSPAMon at flownet.com> wrote:
> > >> > I'm writing a system in a different language but want to use a Python
> > >> > library. I know of lots of ways to do this (embed a Python
> > >> > interpreter,
> > >> > fire up a python server) but by far the easiest to implement is to
> > >> > have
> > >> > the main program spawn a Python interpreter and interact with it
> > >> > through
> > >> > its stdin/stdout.
> > >>
> > >> Or, open python using a socket.
> > >
> > > You mean a TCP/IP socket? Or a unix domain socket? The former has
> > > security issues, and the latter seems like a lot of work. Or is there
> > > an easy way to do it that I don't know about?
> >
> > I was referring to unix domain sockets or more specifically stream
> > pipes. I guess it depends what language you are using and what libraries
> > you have access to. Under C, working with stream pipes is no more trivial
> > then using pipe(). You can simply create the socket descriptors using
> > socketpair(). Keep one of the descriptors for your process and pass the
> > other to the python child process as both stdin and stdout.
>
> Ah. That is in fact exactly what I am doing, and that is how I first
> encountered this problem.
>
> rg
And now I have encountered another problem:
-> print sys.stdin.encoding
<- None
But when I run from a terminal:
[ron at mickey:~]$ python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.stdout.encoding
'UTF-8'
I thought the value of sys.stdin.encoding was hard-coded into the Python
executable at compile time, but that's obviously wrong. So how does
Python get the value of sys.stdin.encoding?
rg
More information about the Python-list
mailing list