Skip to content

About the inspect method #6

@dentarg

Description

@dentarg

I see that you have implemented an inspect method in Result.

In Ruby, this method is a bit special, here is the Ruby documentation about #inspect

Returns a string containing a human-readable representation of obj. The default inspect shows the object’s class name, an encoding of the object id, and a list of the instance variables and their values (by calling inspect on each of them). User defined classes should override this method to provide a better representation of obj.

result
=> #<Twingly::Search::Result:0x3ff7adcbe3d4 @posts, @number_of_matches_returned=10, @number_of_matches_total=3035221>

Is it possible to do the same thing in python?

So instead of

>>> result.inspect()
u'#<Result:0x4306258000 @posts, @number_of_matches_returned=10, @number_of_matches_total=676, >'

we can do

>>> result
<twingly_search.result.Result object at 0x100ac4850>

but have the nice string :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions