Skip to content
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

Possible enhancement for DiscreteDP class #180

Closed
jstac opened this issue Sep 7, 2015 · 2 comments
Closed

Possible enhancement for DiscreteDP class #180

jstac opened this issue Sep 7, 2015 · 2 comments

Comments

@jstac
Copy link
Contributor

jstac commented Sep 7, 2015

@oyamad

After talking this over with @mmcky and @thomassargent30 I have a quick suggestion / question.

Say we run

results = ddp.solve(method='policy_iteration')

Now I want to interact with results in IPython. Let's say I don't remember exactly what's returned, which is probably the most common scenario. Ideally I would be able to type results.[tab key] and see all its attributes, or at least the ones I'm interested in.  At the moment I just get the attributes of a dict.  

I think it's worth improving this because it saves people having to look up the docs when they want to interact with the results, particularly since results contains quiet a few objects of interest.

To me, first best would be that results.[tab key] shows exactly the objects we are trying to return to the user, as they are now specified, and little else (i.e., no miscellaneous methods or attributes that clutter the pop up menu).

How about returning a namedtuple populated with these objects? That would pretty much do the job, and namedtuples are in the standard library...

@oyamad
Copy link
Member

oyamad commented Sep 8, 2015

@jstac Thanks for your suggestion.

I have never used namedtuple and am happy to learn about it. But before that, what about this solution from Stack Overflow?

def __dir__(self):
    return self.keys()

With the latest version of IPython, results.[tab key] will show only the keys (i.e., attributes) of results. (This seems to be a feature recently added; in older versions of IPython, this will show the methods or attributes of dict as well. See ipython/ipython#8330.)

@jstac
Copy link
Contributor Author

jstac commented Sep 8, 2015

@oyamad That sounds just right. Would you mind to try it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants