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: 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 Subject: Re: redirect standard output problem Date: Sat, 22 Dec 2012 16:02:15 -0500 References: <0d7c7686-8b06-4dc2-8b57-3f22d1ef93ae@googlegroups.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: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 12/22/2012 10:15 AM, Chris Angelico wrote: > On Sun, Dec 23, 2012 at 2:07 AM, iMath 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 >>> 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