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
Return a string containing a printable representation of an object. For many types, this function makes an attempt to return a string that would yield an object with the same value when passed to eval(), otherwise the representation is a string enclosed in angle brackets that contains the name of the type of the object together with additional information often including the name and address of the object.
Maybe we could try to implement this "strictly", i.e. return something like "'<class '__main__.OpticalModel'>(name='name', desc='desc', oscillators=[<class '__main__.Oscillators.Lorentz'>(1,2,3), <class '__main__.Oscillators.Gauss'>(2,1,3), ])'"
In this way, om2 = eval(return(om1))
would create the same optical model.
PS: I am not sure __main__ is correct, I am not really aware of how it should be written.
For the oscillators I'm doing something like that already (provided is well done). if you do
d2 = eval(repr(d1))
you will get a new oscillator d2 with the same parameters as d1. This works at least in the interpreter when the oscillators are directly in the base namespace.
I'm already using this idea to reconstruct oscillators loaded from json. This works with the slight hack of importing all the oscillators in OpticalModel in their local namespace. Will make a new issue for this.
As the title says, what to do with the repr method in OpticalModel?
The text was updated successfully, but these errors were encountered: