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

Shortcuts for accessing dataset attributes #53

Open
ajasja opened this issue May 28, 2014 · 4 comments
Open

Shortcuts for accessing dataset attributes #53

ajasja opened this issue May 28, 2014 · 4 comments

Comments

@ajasja
Copy link
Member

ajasja commented May 28, 2014

Typing spectrum.dataset.x etc gets tiresome.
By overriding __getattr__ and __setattr__ it should be quite easy to redirect spectrum.x into returning spectrum.dataset.x (and of course all the other attributes of the dataset).

@ajasja ajasja added this to the 0.1 milestone May 28, 2014
@odarbelaeze
Copy link
Contributor

What about a property, could be a more pythonic to archive the same result?

@ajasja
Copy link
Member Author

ajasja commented May 28, 2014

Hmm you mean the @property decorator? Could we generate all the members of the dataset as properties automatically?

The advantage of __getattr__ would be that by overriding one method all the datasets attributes would be automatically rerouted.

The pseudocode would go like

def __getattr__(name):
    if dataset has member with name then:
        return dataset.getattr(name)
   else
        raise exception

@odarbelaeze
Copy link
Contributor

I don't think a property decorator would do that, but is it really good to expose all the members of dataset to the spectrum class? If so what about making spectrum to o be a subclass of dataset?

@ajasja
Copy link
Member Author

ajasja commented May 28, 2014

Yes, that would be another option. But we did not do this, since we envisioned, that there could be several types of different spectra. So the importer fo CSV could be used to load an UVSpectra, an IRSpectra etc... And dataset was the decoupling element, since all importers return a dataset and all spectra/exporters accept a dataset.

Actually the __getattr__ trick is very similar to subclassing (what would be the diffrences?) while allowing us maximum flexibility.

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