1

I am very new to python so I don't know whether what I am trying to do is doable or not.

I would like to know if I can quote a variable within a python program to retrieve an object attribute.

Below the relevant code which is probably better than wording:

for Volume in volumes:
   row.update(Volume.attachments[0])
   for Key in csv_file_fields:   # Key contains names which are attributes
      try:                       # of the Volume object
        row[Key] = Volume.Key    # But here I get the error that Key
                                 # is not a valid attribute

Is there a way in python to achieve the variable substitution I get in bash by doing $(Key)?

lucasnadalutti
  • 5,818
  • 1
  • 28
  • 48
Rockyjoe
  • 23
  • 3

1 Answers1

0

You want:

row[Key] = getattr(Volume, Key)
lucasnadalutti
  • 5,818
  • 1
  • 28
  • 48