I've been making a few things pretty-printable, but I think we should make some decisions about what functions return what kind of string for our objects.
In particular, I'm thinking about things like PathMovers and Ensembles, where it would be nice to have a clean string representation. If I want to check that my move scheme from a network is correct, seeing <openpathsampling.pathmover.ReplicaExchangeMover at 0x114025650> doesn't help very much.
The common functions here would be __str__ and __repr__. As I understand it, __str__ should be easily human-readable, and __repr__ should be as close to code that reproduces the object as possible, and most importantly, should be unambiguous. I think we may want to create a third function to print something which is not quite code and not quite human-readable. Maybe call that .description() or something like that?
Consider Ensemble as an example. Right now, Ensemble.__str__ prints a set-theoretic description of the ensemble. This is unambiguous, but not really human readable (at least, not for complicated ensembles). I think this should be moved to the .description (or whatever we call it).
In many cases, we can assign a name to an ensemble (Interface 1 from State B, Minus Interface State A), and I've been working on having my network code create those names by default. I think this is what the __str__ object should print, with a fallback to calculate something like the .description (but using name for subobjects) if self.name is not available.
Also, __repr__ (which we have rarely implemented) should be made more like its standard behavior, which is unambiguous and often code-like.
Basically, my suggestion is this:
__str__ : human readable, simple, not necessarily unambiguous -- usually self.name if available
description : sort-of human readable, unambiguous
__repr__ : code-like, unambiguous
I've been making a few things pretty-printable, but I think we should make some decisions about what functions return what kind of string for our objects.
In particular, I'm thinking about things like
PathMovers andEnsembles, where it would be nice to have a clean string representation. If I want to check that my move scheme from a network is correct, seeing<openpathsampling.pathmover.ReplicaExchangeMover at 0x114025650>doesn't help very much.The common functions here would be
__str__and__repr__. As I understand it,__str__should be easily human-readable, and__repr__should be as close to code that reproduces the object as possible, and most importantly, should be unambiguous. I think we may want to create a third function to print something which is not quite code and not quite human-readable. Maybe call that.description()or something like that?Consider
Ensembleas an example. Right now,Ensemble.__str__prints a set-theoretic description of the ensemble. This is unambiguous, but not really human readable (at least, not for complicated ensembles). I think this should be moved to the.description(or whatever we call it).In many cases, we can assign a name to an ensemble (
Interface 1 from State B,Minus Interface State A), and I've been working on having my network code create those names by default. I think this is what the__str__object should print, with a fallback to calculate something like the.description(but usingnamefor subobjects) ifself.nameis not available.Also,
__repr__(which we have rarely implemented) should be made more like its standard behavior, which is unambiguous and often code-like.Basically, my suggestion is this:
__str__: human readable, simple, not necessarily unambiguous -- usuallyself.nameif availabledescription: sort-of human readable, unambiguous__repr__: code-like, unambiguous