Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #35389

Re: redirect standard output problem

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'win32': 0.03; 'output': 0.04; 'socket': 0.05; 'sys': 0.05; 'tkinter': 0.07; 'works.': 0.07; 'python': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'sep': 0.09; 'streams.': 0.09; 'sys.stdout': 0.09; 'terry': 0.09; 'windows,': 0.09; 'gui': 0.11; 'dec': 0.15; 'slightly': 0.15; 'different,': 0.16; 'exe': 0.16; 'fiddle': 0.16; 'idle,': 0.16; 'invisible': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'wrote:': 0.17; 'handles': 0.18; 'jan': 0.18; '>>>': 0.18; 'mostly': 0.20; 'bit': 0.21; 'import': 0.21; 'sends': 0.22; 'subject:problem': 0.22; 'runs': 0.22; 'connected': 0.24; 'command': 0.24; 'header:In-Reply-To:1': 0.25; 'header:User- Agent:1': 0.26; 'leave': 0.26; 'am,': 0.27; 'header:X-Complaints- To:1': 0.28; 'skip:( 20': 0.28; 'chris': 0.28; 'run': 0.28; 'post': 0.28; '>>>>': 0.29; 'i/o': 0.29; 'case,': 0.29; 'window': 0.30; 'expect': 0.31; 'code': 0.31; 'print': 0.32; 'function.': 0.33; 'idle': 0.33; 'to:addr:python-list': 0.33; 'likely': 0.33; 'text': 0.34; 'false': 0.35; 'especially': 0.35; 'remote': 0.35; 'there': 0.35; 'received:org': 0.36; 'but': 0.36; 'method': 0.36; 'should': 0.36; 'two': 0.37; 'uses': 0.37; 'why': 0.37; 'subject:: ': 0.38; 'mean': 0.38; 'object': 0.38; 'some': 0.38; 'things': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; "you've": 0.61; 'procedure': 0.61; "you'll": 0.62; 'box.': 0.65; 'believe': 0.69; 'connection.': 0.75; 'difference!': 0.84; 'interaction.': 0.84; 'none!': 0.84; 'received:fios.verizon.net': 0.84; 'adopting': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Re: redirect standard output problem
Date Sat, 22 Dec 2012 16:02:15 -0500
References <cf470745-6ee6-464c-b936-154a869af997@googlegroups.com> <mailman.1141.1356074653.29569.python-list@python.org> <0d7c7686-8b06-4dc2-8b57-3f22d1ef93ae@googlegroups.com> <CAPTjJmoznK_oRo8OsnmddjT2TnVRBmj7HDmjzupdsv1Mmb8vTQ@mail.gmail.com>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0
In-Reply-To <CAPTjJmoznK_oRo8OsnmddjT2TnVRBmj7HDmjzupdsv1Mmb8vTQ@mail.gmail.com>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1212.1356210160.29569.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1356210160 news.xs4all.nl 6876 [2001:888:2000:d::a6]:59702
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:35389

Show key headers only | View raw


On 12/22/2012 10:15 AM, Chris Angelico wrote:
> On Sun, Dec 23, 2012 at 2:07 AM, iMath <redstone-cold@163.com> wrote:
>> when I run it through command line ,it works ok ,but when I run it through IDLE , only print A but leave out 888
>> so why ?
>
> Because IDLE has to fiddle with stdin/stdout a bit to function. Try
> adopting Dave's recommendation - you'll likely find that it then
> works.
>
> Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600
> 32 bit (Intel)] on win32
>>>> sys.stdout is sys.__stdout__
> True
>
> The same in IDLE:
>>>> sys.stdout is sys.__stdout__
> False

In particular, on Windows,
 >>> import sys
 >>> sys.stdout
<idlelib.run._RPCOutputFile object at 0x0000000002D852E8>
 >>> sys.__stdout__
 >>>

In other words, sys.__stdout__ is None!

To explain: IDLE runs in two processes connected by sockets. There is 
one process for user code and one for the gui. The user code process 
should be invisible as the gui process handles all user interaction. On 
Windows, this mean a process with no window and no input/output, which 
is what the pythonw (windowless) exe is for. (I believe IDLE on *nix 
uses an invisible window instead.) In any case, sys.stdout is set to a 
remote procedure call object that sends output to the socket connection. 
The gui process reads the socket and call the tkinter method to all text 
to a tk text box.

> Whenever you work in IDLE, expect that some things will be slightly
> different, mostly to do with standard I/O streams. So when you post
> issues that you've come across, please state that you're using IDLE -
> it likely makes a difference!

Indeed! Especially for i/o issues, retest in the command window;-).

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

redirect standard output problem iMath <redstone-cold@163.com> - 2012-12-20 21:23 -0800
  Re: redirect standard output problem Chris Angelico <rosuav@gmail.com> - 2012-12-21 18:24 +1100
    Re: redirect standard output problem iMath <redstone-cold@163.com> - 2012-12-22 07:07 -0800
      Re: redirect standard output problem Chris Angelico <rosuav@gmail.com> - 2012-12-23 02:15 +1100
      Re: redirect standard output problem Terry Reedy <tjreedy@udel.edu> - 2012-12-22 16:02 -0500
    Re: redirect standard output problem iMath <redstone-cold@163.com> - 2012-12-22 07:07 -0800
  Re: redirect standard output problem Hans Mulder <hansmu@xs4all.nl> - 2012-12-21 14:42 +0100
  Re: redirect standard output problem Dave Angel <d@davea.name> - 2012-12-21 09:36 -0500

csiph-web