Giter VIP home page Giter VIP logo

Comments (10)

 avatar commented on May 18, 2024

[ LP comment 1 by: anatoly techtonik, on 2009-06-04 12:33:54.822394+00:00 ]

from ipython.

Drekin avatar Drekin commented on May 18, 2024

I'd like to ask about the interaction between IPython console run in Windows command prompt and sys.std* objects. I would think there would be no interaction, because IPython console uses other means implementing iteractive io to provide features as colors and autocompletition. However for example setting sys.stdout = 3 produces infinite stream of errors.

There is a long standing issue with Unicode charcters in Python interactive console being run on Windows (http://bugs.python.org/issue1602). I'm trying to workaround by using custom stream objects, but there is some weird interaction witch IPython interactive console, see Drekin/win-unicode-console#2.

from ipython.

takluyver avatar takluyver commented on May 18, 2024

I would certainly expect setting sys.stdout to an integer to break things spectacularly.

From IPython's point of view, we use sys.stdout as normal, i.e. using print() (and possibly sys.stdout.write() in some places). As you've already noticed, pyreadline does things with it.

from ipython.

Drekin avatar Drekin commented on May 18, 2024

So things like printing colorful In[] and Out[] are done by calling some pyreadline api? But pyreadline talks to Windows console directly, so sys.std* objects are bypassed, so I don't get how their changing could affect displaying colorful propmt.

from ipython.

takluyver avatar takluyver commented on May 18, 2024

We write to stdout ANSI control codes for changing colours etc., which are recognised by terminal emulators on *nix systems. On Windows, pyreadline intercepts those codes with a custom sys.stdout object, and calls the appropriate Windows console functions. So if you replace sys.stdout back to sommething like the default, you probably see the effects of sending those ANSI control sequences directly to the Windows terminal.

from ipython.

Drekin avatar Drekin commented on May 18, 2024

That makes sense, but why can't I see the wrapper object? sys.stdout in IPython console is standard output stream and sending ANSI control sequences doesn't work with it.

from ipython.

takluyver avatar takluyver commented on May 18, 2024

Strange, I'm not sure about that, and I don't have my Windows VM handy to investigate.

I've just looked at our prompts code - we do just generate a string with ANSI control sequences, and pass that to input().

from ipython.

Drekin avatar Drekin commented on May 18, 2024

Actually, passing the ANSI sequence to input() works. The input function doesn't use sys.stdout for prompt when readline is available, but when sys.stdout is chaged, it uses the changed variant. So it's again fault of complicated interaction between readline and Python core. See http://bugs.python.org/issue17620.

from ipython.

fperez avatar fperez commented on May 18, 2024

It sounds like we should close this one and leave the Python 17620 issue you reference above for the follow-up, right?

from ipython.

Carreau avatar Carreau commented on May 18, 2024

With all the recent prompt_toolkit refactor I'm going to close this one which is likely not relevant anymore after 7 years. Thanks all, please reopen a new issue if needed.

from ipython.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.