Python Forum
Is it possible to loop through class attributes via string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is it possible to loop through class attributes via string?
#2
What is your actual purpose on doing this determines the result.

From the object of the class
>>> class Klass:
...     def __init__(self):
...             self.var = 1
...             self.pot = 'test'
... 
>>> obj = Klass()
>>> obj.__dict__
{'var': 1, 'pot': 'test'}
Recommended Tutorials:
Reply


Messages In This Thread
RE: Is it possible to loop through class attributes via string? - by metulburr - Feb-04-2018, 04:46 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [solved] Classes, assign an attributes to a class not to instances.. SpongeB0B 4 987 May-20-2023, 04:08 PM
Last Post: SpongeB0B
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 1,083 Sep-19-2022, 02:32 AM
Last Post: Xeno
  Loop through a list of string oldtrafford 4 1,517 Mar-24-2022, 05:30 PM
Last Post: deanhystad
  [Solved] Novice question to OOP: can a method of class A access attributes of class B BigMan 1 1,350 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  Distinguishing different types of class attributes Drone4four 4 2,143 Feb-21-2022, 06:34 PM
Last Post: deanhystad
  Loop through a list of string oldtrafford 3 1,756 Feb-15-2022, 04:42 PM
Last Post: snippsat
  loop for dynamic cut string - cleaner way? korenron 4 2,003 Nov-22-2021, 02:30 PM
Last Post: korenron
  I am trying to reverse a string using loop codinglearner 4 2,207 Sep-28-2021, 10:46 PM
Last Post: Pedroski55
  Calls to Attributes of a Class SKarimi 3 3,448 Apr-22-2021, 04:18 PM
Last Post: SKarimi
  Convert string to JSON using a for loop PG_Breizh 3 3,013 Jan-08-2021, 06:10 PM
Last Post: PG_Breizh

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020