Interactive scripts (back on topic for once) [was Re: The "loop and a half"]
Terry Reedy
tjreedy at udel.edu
Fri Oct 6 16:11:16 EDT 2017
On 10/6/2017 1:32 PM, Chris Angelico wrote:
> On Sat, Oct 7, 2017 at 4:05 AM, Grant Edwards <grant.b.edwards at gmail.com> wrote:
>> On 2017-10-06, Thomas Jollans <tjol at tjol.eu> wrote:
>>
>>> Seriously? sys.stdin can be None? That's terrifying.
>>
>> Why?
>>
>> Unix daemons usually run with no stdin, stderr, or stdout.
>>
>> And yes, people do write Unix daemons in Python.
>
> Hmm, but usually I would expect them still to HAVE those streams,
> they're just connected to /dev/null or something. I don't think they
> would actually fail to exist, would they?
On Windows, a file run with pythonw.exe (no console) starts with
sys.[__]std[in|out|err][__] (6 entries) set to None. The program can
reset them as it pleases. In an IDLE user process, the non-dunder names
are set to objects that communicate with the IDLE GUI process.
>>> import sys; sys.__stdin__, sys.stdin
(None, <idlelib.run.PseudoInputFile object at 0x0000014639AA7E10>)
GUI programs interact with the OS and thence users through event streams
rather than character streams. (Note that terminal escape sequences are
character-encoded events.) That is why automating a GUI usually
requires a special program than can generate and inject events into the
event queue read by the GUI program.
--
Terry Jan Reedy
More information about the Python-list
mailing list