0

I have a database object db with fields

db.one = 1
db.two = 2
db.three = 3

Is there any way to do something like

require_comparison_list = ["one", "three"]
for field in dir(db):
   if field in reqire_comparison_list:
       print(db.field)

where db.field will give me 1 and 3.

Thank you

Daniel Walker
  • 5,220
  • 3
  • 18
  • 39
Norman Kuo
  • 115
  • 7
  • Actually nvm, this is what I need: https://stackoverflow.com/questions/25150955/python-iterating-through-object-attributes?answertab=active#tab-top – Norman Kuo Dec 17 '21 at 04:19

0 Answers0