On 12/22/2012 10:15 AM, Chris Angelico wrote:
On Sun, Dec 23, 2012 at 2:07 AM, iMath <redstone-c...@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

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to