-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
display methods #13
Comments
You don't need both since |
I agree with @albop. Defining only |
Ok great, I'm glad we got updated suggestions. Thanks for the thoughts. If
|
In some of my work I use |
I've read a bit about these issues. Apparently In case there is no clear content to put in the There are other options for more detailed or more user friendly output : pretty-print strings and ipython representation for the display method. References are http://ipython.org/ipython-doc/2/api/generated/IPython.lib.pretty.html and http://ipython.org/ipython-doc/dev/api/generated/IPython.core.formatters.html . These are less important in the short tem. It would give a structure like: class E:
def __init__(self, gamma=2, eta=1):
pass
def __repr__(self):
# machine parseable result: eval(e.__repr__) should return e (if possible)
return "E(gamma=2, eta=1)"
def __str__(self):
# Human friendly text
return 'Model\n gamma = 2\n eta=1'
def _repr_pretty_(self,p,cycle):
# Pretty print representation
p.text("Model E\n gamma = 2\n eta=1")
def _repr_html_(self):
# nice html representation for the notebook
return "<b>Model</b></p>gamma = 2</p>eta=1" |
I would like like to revisit this and potentially implement it in the next few days. I wanted to ping this issue to give people a chance to comment on what they would like to see in these. I like what @albop presented in the previous comment. We might try something like this (for starters, this is really just to get a conversation going): def __str__(self):
m = "GrowthModel:\n"
m += " - beta (discount factor): %.3f\n" % self.beta
m += " - u (utility function): %s\n" % self.u.__str__()
m += " - f (production function): %s\n" % self.f.__str__()
m += " - grid: np.linspace(1e-6, %.2f, %i)\n" % (self.grid.max(),
self.grid.size)
return m
def __repr__(self):
m = "GrowthModel(beta=%.3f, grid_max=%.3f, grid_size=%i)"
return m % (self.beta, self.grid.max(), self.grid.size) which produces the following:
These are definitely not the only possibilities, but I just wanted to throw them out there as examples of two having a very descriptive We could also add other things like Does anyone have any suggestions? |
This would be great to have done. I don't have any concrete views on how. I guess I would be in favor of keeping it fairly simple. For things like the growth model it might be sensible to print out a link to the relevant page on quant-econ.net --- but I don't want push this idea too hard because I know we want to decouple library and website. Feel free to ignore. |
That's a good idea. I'm in favor of it as I see the modes more as serving more of a pedagogical purpose than as standalone tools. What did you think about the sketch outlined above? |
Looks great. |
@spencerlyon2 I think your suggestion is excellent. I have used Is there a way we could use sympy to represent the functions? |
I hadn't thought of sympy. I was thinking about trying to use |
Closing in favor of #114 |
Right now none of our classes print helpful messages when queried at the repl. Let's remedy this by implementing
__str__
,__repr__
, and__unicode__
methods. The easiest thing would probably be to just implement__unicode__
and have the others just call and return its value:Here is a list of classes we need to update:
The text was updated successfully, but these errors were encountered: