GithubHelp home page GithubHelp logo

Comments (9)

Psycojoker avatar Psycojoker commented on August 17, 2024

Hello,

There is great chances that this is actually already fixed but unreleased (see: #44). Can you try using RedBaron master to see if this works please?

I'll do a bugfix release if it's the case.

Thanks for reporting :)

from redbaron.

remram44 avatar remram44 commented on August 17, 2024

I can reproduce the bug on master; zmq's sys.stdout does have fileno(), it just raises when called.

from redbaron.

remram44 avatar remram44 commented on August 17, 2024

This should be a simple matter of catching UnsupportedOperation, however I do not understand why the isatty() check is here to begin with. __repr__() works differently depending on what sys.stdout is, regardless of whether __repr__() is going there or not?

from redbaron.

Psycojoker avatar Psycojoker commented on August 17, 2024

Yes, in a ipython shell, repr displays the selected code (highlighted with pygment) like BeautifulSoup displays you the selected html. But when running a script you might not know where you are and what you have selected at this point so we display a more common repr (much like any python object).

I'm going to look at it in some minutes.

from redbaron.

remram44 avatar remram44 commented on August 17, 2024

The problem with that approach is that you have no accurate way of knowing if the result of __repr__ is eventually meant to be printed in the terminal or not. In IPython, the kernel is not attached to a terminal, and yet the result is sent through a ZMQ socket and printed. In contrast, a non-interactive function might still happen in a process which is still connected to a terminal.

The current approach already does weird stuff, for example:

>>> tree.help
<bound method NodeList.help of 0   self.get_input('some_port')
1   u'\n'
2   a = self.force_get_input('something', 2)
3   u'\n'
4   if False:
        self.set_output('port_name', False)

>

AFAIK beautifulsoup doesn't try anything funny here either (link).

I'm not sure what to recommend though because __str__()'s output is indeed useful 😢

from redbaron.

Psycojoker avatar Psycojoker commented on August 17, 2024

Yes, BeautifulSoup always print the html code which is fine. In our case we sometime ends up printing formatting information like white spaces which turns out to be extremely confusing for the user.

So, after one quick google search "how to detect that you are in a python shell" we ends up with this situation that doesn't seems very optimal :/

Right now I don't know have an opinion on the best approach to have. I'll start by fixing it for ipython and catching other exceptions to fall back on a default behavior.

from redbaron.

Psycojoker avatar Psycojoker commented on August 17, 2024

After playing with "def repr_html" of the notebook this end up looking like this:
2015-01-13-235917_754x677_scrot

Should be way more usable. It's pushed on master.

Tell me if you find any more bugs ;)

from redbaron.

Psycojoker avatar Psycojoker commented on August 17, 2024

Closing this issue for now, don't hesitate to complain/reopen it/open other issues if needed.

from redbaron.

remram44 avatar remram44 commented on August 17, 2024

This is great, thanks 😃

from redbaron.

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.