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

Provide __list__(self) along the lines of __str__(self) #68523

Closed
RohithPR mannequin opened this issue May 31, 2015 · 2 comments
Closed

Provide __list__(self) along the lines of __str__(self) #68523

RohithPR mannequin opened this issue May 31, 2015 · 2 comments
Labels
type-feature A feature request or enhancement

Comments

@RohithPR
Copy link
Mannequin

RohithPR mannequin commented May 31, 2015

BPO 24335
Nosy @ethanfurman

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2015-05-31.08:03:53.810>
created_at = <Date 2015-05-31.06:53:15.228>
labels = ['type-feature']
title = 'Provide __list__(self) along the lines of __str__(self)'
updated_at = <Date 2015-05-31.08:03:53.799>
user = 'https://bugs.python.org/RohithPR'

bugs.python.org fields:

activity = <Date 2015-05-31.08:03:53.799>
actor = 'ethan.furman'
assignee = 'none'
closed = True
closed_date = <Date 2015-05-31.08:03:53.810>
closer = 'ethan.furman'
components = []
creation = <Date 2015-05-31.06:53:15.228>
creator = 'Rohith.PR'
dependencies = []
files = []
hgrepos = []
issue_num = 24335
keywords = []
message_count = 2.0
messages = ['244522', '244525']
nosy_count = 2.0
nosy_names = ['ethan.furman', 'Rohith.PR']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue24335'
versions = ['Python 3.6']

@RohithPR
Copy link
Mannequin Author

RohithPR mannequin commented May 31, 2015

It would be cleaner to do list(obj) than obj.to_list() (Eg: in numpy).

PS: this is the first time that I'm contributing to python. If this feature request is accepted can I work on it myself?

@RohithPR RohithPR mannequin added the type-feature A feature request or enhancement label May 31, 2015
@ethanfurman
Copy link
Member

If somebody wants their class to support being turned into a list, the obvious answer is to have that class support iteration, and there are already three ways to do that:

  • supply an __iter__ that returns a separate iterator

  • supply an __iter__/next that makes instances of the class be their own iterators

  • supply a __getitem__ that works with ints (0, 1, 2, ...) to return the values.

If numpy objects do not already support any of those three methods it probably means there isn't just one way to want to iterate through them, but you'll have to take that up with the numpy folks.

In the future you should discuss enhancement ideas on the Python Ideas list first.

Your contributions are welcome, but you'll need to sign the Contributors License Agreement first (found at https://www.python.org/psf/contrib/contrib-form/).

If I have misunderstood what you intended, please provide more context and an example.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

1 participant