-2

I want to evaluate a string to accomplish the following. The string will be coming from an xml config file. This is how I would configure a serial option without a config file:

import serial
ser = serial.Serial(/dev/ttyUSB0)
ser.parity = serial.PARITY_MARK
...configure other options

Now this is the equivalent of what I want to do but...

   str = "PARITY_MARK"
   ser.parity = some_wrapper("serial." + str)
dpetican
  • 771
  • 1
  • 5
  • 12

1 Answers1

3

Are you looking for getattr?

getattr(serial, 'PARITY_MARK') == serial.PARITY_MARK
salezica
  • 74,081
  • 25
  • 105
  • 166