I know eval
is bad, I'm pretty new to coding.
I'm using config parser to define motors that open output gates to divert parts
from my config file:
[Motor]out1=["Screw", "board0.motor1"]
Code
out1=json.loads(config['Motor']['out1'])
board0 = MotorKit(address= int(config['Motor']['board0'], 16))
def openMotor(m):
eval(m).throttle = 1
time.sleep(0.1)
eval(m).throttle = 0.2
def open_gate(part):
if part == out1[0]:
openMotor(out1[1])
open_gate("screw")
How do I not use eval
? but be able to set the attritbute board0.motor1.throttle
in the openMotor
function?