python method to initialize mass variable with random data types
hi, in python, i got a massive signals with random data types need to initialize, below is a sample:
import rclpy
from std_msgs.msg import Float32
from std_msgs.msg import Int8
x = Float32()
y = Int8()
x.data = 0.0
y.data = 0
where the initials of = 0.0
or = 0
depends on data types, when i coding i need to check type manually first then decide to write 0.0
or 0
, is quite not smart.
if i directly make them all like
x.data = 0
y.data = 0
it's easy to coding but i got error
AssertionError: The 'data' field must be of type 'int'
is there a way like auto
in cpp
to make this case easier to coding?
like auto_type()
below
import rclpy
from std_msgs.msg import Float32
from std_msgs.msg import Int8
x = Float32()
y = Int8()
x.data = auto_type(0)
y.data = auto_type(0)
Asked by fury.nerd on 2022-10-17 19:59:46 UTC
Answers
turn out to use the following code temporarily:
x.data # = 0
y.data # = 0
Asked by fury.nerd on 2022-10-17 20:16:16 UTC
Comments