Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What to do with __repr__ of OpticalModel? #64

Open
ivergara opened this issue Jun 10, 2016 · 2 comments
Open

What to do with __repr__ of OpticalModel? #64

ivergara opened this issue Jun 10, 2016 · 2 comments

Comments

@ivergara
Copy link
Collaborator

As the title says, what to do with the repr method in OpticalModel?

@francescorandi
Copy link
Owner

francescorandi commented Jun 13, 2016

Reading from the official docs for repr()

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.

@ivergara
Copy link
Collaborator Author

ivergara commented Jun 13, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants