Rosanswers logo

I find that messages loaded from a rosbag via the Python API, have a weird class attribute:

import rosbag
from sensor_msgs.msg import PointCloud2

# Round-trip a PointCloud2 message to a rosbag and back
bag = rosbag.Bag('test.bag', 'w')
    scan = PointCloud2()
    print("__class__should be: \n{}".format(scan.__class__))
    bag.write('scan', msg)

bag = rosbag.Bag('test.bag')
for topic, msg, t in bag.read_messages(topics=['scan']):
    print("But it comes out as: \n{}".format(msg.__class__))

The output:

__class__should be: 
<class 'sensor_msgs.msg._PointCloud2.PointCloud2'>
But it comes out as: 
<class 'tmpf1u1_e._sensor_msgs__PointCloud2'>

Is this a bug, or a feature?

ROS Indigo, Ubuntu 14, Python 2.7

Originally posted by Rick Armstrong on ROS Answers with karma: 567 on 2018-02-25

Post score: 1


1 Answer 1


Rosanswers logo

This is a feature, not a bug.

Instead of using or relying on the local message definitions, which may not match the message definitions stored in the bag file (or may not exist at all!), the python API for rosbag generates class definitions on the fly for each message type stored in the bag file. Unfortunately, these auto-generated classes don't have the same names as the original classes.

Originally posted by ahendrix with karma: 47576 on 2018-02-26

This answer was ACCEPTED on the original site

Post score: 2


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.