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?
#3
I'm currently trying to create a button gallery, however the button's functionality is triggered but a button attribute function. The reason for iteration through all these buttons. IE
self.PoseSlot_1.clicked.connect(self.printonetwoThree2)
self.PoseSlot_2.clicked.connect(self.printonetwoThree2)
self.PoseSlot_3.clicked.connect(self.printonetwoThree2)
self.PoseSlot_4.clicked.connect(self.printonetwoThree2)
...
is to create a default function on the click command if there is a null value.

I just figure I could make a loop so i didn't have to copy and paste the code like above

Oh yea also, All of the attributes are already generated through the UI file.* "PoseSlot_ ..."
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
Question [solved] Classes, assign an attributes to a class not to instances.. SpongeB0B 4 994 May-20-2023, 04:08 PM
Last Post: SpongeB0B
  PyRun_SimpleFile calling multiprocessing Python Class cause endless init loop Xeno 2 1,088 Sep-19-2022, 02:32 AM
Last Post: Xeno
  Loop through a list of string oldtrafford 4 1,525 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,356 Mar-14-2022, 11:21 PM
Last Post: deanhystad
  Distinguishing different types of class attributes Drone4four 4 2,149 Feb-21-2022, 06:34 PM
Last Post: deanhystad
  Loop through a list of string oldtrafford 3 1,761 Feb-15-2022, 04:42 PM
Last Post: snippsat
  loop for dynamic cut string - cleaner way? korenron 4 2,013 Nov-22-2021, 02:30 PM
Last Post: korenron
  I am trying to reverse a string using loop codinglearner 4 2,210 Sep-28-2021, 10:46 PM
Last Post: Pedroski55
  Calls to Attributes of a Class SKarimi 3 3,459 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