eyurtsev / FlowCytometryTools

A python package for visualization and analysis of high-throughput flow cytometry data
https://eyurtsev.github.io/FlowCytometryTools/
MIT License
113 stars 46 forks source link

More informative BaseObject.__repr__ #6

Closed jlumpe closed 9 years ago

jlumpe commented 9 years ago

I've noticed the default __repr__ method for FCMeasurement just returns repr(self.ID) (inherited from BaseObject). This makes things slightly confusing if I'm working from the interpreter and type a variable in to remind myself what it is, as it looks like a string. Example:

In [1]: import FlowCytometryTools

In [2]: sample = FlowCytometryTools.FCMeasurement('my_sample', '/path/to/my_sample.fcs')

In [3]: sample
Out[3]: 'my_sample'

I believe it is typically preferred in python to have eval(repr(my_obj)) == my_obj when practical, but I'm not sure it is in this case. The other common pattern is to make it similar to the default for new-style classes, which is something like '<mymodule.MyClass at 0x0000000>', with the address possibly replaced by something more informative. I thought something like the following would help:

In [6]: sample
Out[6]: <FCMeasurement 'my_sample'>

This style is consistent with existing conventions, makes the type of the object clear, and shows the ID which should uniquely identify the instance. I chose not to add the module because I thought FlowCytometryTools.core.containers.FCMeasurement was a bit too verbose. Making the change in BaseObject looks like it should work well in all derived classes which do not already override __repr__.

eyurtsev commented 9 years ago

great