You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Python {{repr}} function should not print anything to the console, it should just return an internal representation of the instance, that can ideally be processed.
[https://docs.python.org/3/reference/datamodel.html#object.repr|https://docs.python.org/3/reference/datamodel.html#object.repr]
In the same way, {{str}} should not call {{print}} either, just return the string that's is going to be printed when user calls {{print}} on the object!
[https://docs.python.org/3/reference/datamodel.html#object.str|https://docs.python.org/3/reference/datamodel.html#object.str]
Many objects in h2o, also implement {{show}}: this methods is used to print complex objects.
Although, it seems to serve the same goal as {{print(obj)}}.
We can keep it for backwards compatibility but the printable string of an instance should be the result of {{str}} implementation, so that:
{code:python}def show(self):
print(self){code}
Among the side effects of this:
in IPython/Jupyter instance details are printed when inspecting method using {{inst.method?}}, {{inst.method??}}.
for debugging, for example when printing request results, we don't have the choice between printing {{repr()}} or {{str()}} (default), so that it prints some of its nested values BEFORE its keys... making this unreadable, non-parsable...
As a default implementation for {{repr}} in H2O classes, I would suggest something like:
{noformat}def repr(self):
r = dict(class='.'.join([self.class.module, self.class.name])
r.update(self.dict)
return repr(r){noformat}
The text was updated successfully, but these errors were encountered:
Python {{repr}} function should not print anything to the console, it should just return an internal representation of the instance, that can ideally be processed.
[https://docs.python.org/3/reference/datamodel.html#object.repr|https://docs.python.org/3/reference/datamodel.html#object.repr]
In the same way, {{str}} should not call {{print}} either, just return the string that's is going to be printed when user calls {{print}} on the object!
[https://docs.python.org/3/reference/datamodel.html#object.str|https://docs.python.org/3/reference/datamodel.html#object.str]
Many objects in h2o, also implement {{show}}: this methods is used to print complex objects.
Although, it seems to serve the same goal as {{print(obj)}}.
We can keep it for backwards compatibility but the printable string of an instance should be the result of {{str}} implementation, so that:
{code:python}def show(self):
print(self){code}
Among the side effects of this:
As a default implementation for {{repr}} in H2O classes, I would suggest something like:
{noformat}def repr(self):
r = dict(class='.'.join([self.class.module, self.class.name])
r.update(self.dict)
return repr(r){noformat}
The text was updated successfully, but these errors were encountered: