Reputation: 75
In C, if you have a variable name and you have a variable you would like to access in protobuf
# define get_value(variable, variable_name, store){ \
store = variable->name_variable_name \
}
Is there a similar functionality in python?
An alternative I can think of is just to do a large if else case
if protobuf_message.type = "LISTENER1":
message = protobuf_message.LISTENER1
elif protobuf_message.listener2 = "LISTENER2":
message = protobuf_message.LISTENER2
I would like to do something like this
listener_type = protobuf_message.type
message = protobuf_message.listener_type
Any advice would be appreciated
Upvotes: 0
Views: 39
Reputation: 531205
You are looking for the getattr
function.
listener_type = protobuf_message.type
message = getattr(protobuf_message, listener_type)
Upvotes: 2