Skip to content

add a __getattr__ to Records so it looks cleaner #13

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

Closed
nhumrich opened this issue Jul 27, 2016 · 4 comments
Closed

add a __getattr__ to Records so it looks cleaner #13

nhumrich opened this issue Jul 27, 2016 · 4 comments
Labels

Comments

@nhumrich
Copy link

nhumrich commented Jul 27, 2016

The syntax row.col looks a lot cleaner than row['col'].
What are you thoughts on adding a __getattr__ method to a Record so that both are possible?

@1st1
Copy link
Member

1st1 commented Jul 27, 2016

We considered having __getattr__ instead of __getitem__ but decided against that, because:

  1. There are a few methods in the Record object, such as .keys(), .values() etc. We don't want field names to clash with Record's API.
  2. Having both __getattr__ and __getitem__ doing the same thing feels non-pythonic.

@1st1 1st1 added the question label Jul 27, 2016
@runfalk
Copy link

runfalk commented Aug 9, 2016

Couldn't this and #17 be solved using a way of specifying an alternative Record class, or factory function, to use? This way the user could even use namedtuples if so desired for memory efficiency.

@1st1
Copy link
Member

1st1 commented Aug 9, 2016

Record is as memory efficient as Python's tuple (it's implemented in pure C). It's also faster than namedtuple to instantiate, since we have a freelist for it.

@1st1
Copy link
Member

1st1 commented Oct 20, 2016

I don't think we'll implement this. Adding __getattr__ will preclude us from adding methods/APIs to the Record class, so let's keep the status quo.

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

No branches or pull requests

3 participants