Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8850043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:48:29+00:00 2026-06-14T12:48:29+00:00

How can I iterate over an object and assign all it properties to a

  • 0

How can I iterate over an object and assign all it properties to a list

From

a = []

class A(object):
    def __init__(self):
        self.myinstatt1 = 'one'
        self.myinstatt2 = 'two'

to

a =['one','two']
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T12:48:30+00:00Added an answer on June 14, 2026 at 12:48 pm

    Don’t create a full fledged class if you just want to store a bunch of attributes and return a list so that your API can consume it. Use a namedtuple instead. Here is an example.

    >>> import collections
    >>> Point = collections.namedtuple('Point', ['x', 'y'])
    >>> p = Point(1, 2)
    >>> p
    Point(x=1, y=2)
    

    If your API just expects a sequence (not specifically a list), you can pass p directly. If it needs a list specifically, it is trivial to convert the Point object to a list.

    >>> list(p)
    [1, 2]
    

    You can even subclass the newly created Point class and add more methods (documentation has details). If namedtuple doesn’t meet your needs, consider sub-classing abc.Sequence Abstract Base Class or using it as a mixin.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that I can iterate over an object's properties like this: for (property
How can i iterate over the (public or private) properties of a php class?
I wish to iterate over an object's properties and change them all to include
lets assume the following simple Object: class Mock: def __init__(self, name, age): self.name =
I have a class with multiple vectors from measurements. I need to iterate over
How can I iterate over all the Django settings? I need to read all
Using jQuery, how can I iterate over an object, and get the unique values
I'm using KnockoutJS to iterate over an object, like this: Now this all works.
Given the following code, how can I iterate over an object of type ProfileCollection?
As I understand, one can iterate the device stack of WDM devices only from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.