-3

I have a list of attributes for an object. I will like to loop over the list and apply them to that object.

Here is what I did:

attrs = ['ClearNoon',
         'ClearSunset',
         'CloudyNoon',
         'CloudySunset',
         'HardRainNoon',
         'HardRainSunset',
         'MidRainSunset',
         'MidRainyNoon',
         'SoftRainNoon',
         'SoftRainSunset',
         'WetCloudyNoon',
         'WetCloudySunset',
         'WetNoon',
         'WetSunset']

for attr in attrs:
    world.set_weather(carla.WeatherParameters.attr)

Unfortunately, this does not work. Any better suggestions please?

JA-pythonista
  • 1,051
  • 11
  • 33
  • What do you want to set the value of the attribute? Do you wanna make new attributes or is it already there – PCM Jul 19 '21 at 10:30

1 Answers1

1

Try using getattr:

world.set_weather(getattr(carla.WeatherParameters, attr))
U12-Forward
  • 65,118
  • 12
  • 70
  • 89