rospy has a logger, use it
topic = 'sensor_msgs/LaserScan/topic'
rospy.loginfo("I will publish to the topic %s", topic)
and some latter in the callback:
def callback(data):
rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)
if you maybe need to collect the data to later use it / reproduce it for analytics purposes then a Rosbag is the way to go :)
import rosbag
from std_msgs.msg import Int32, String
bag = rosbag.Bag('test.bag', 'w')
try:
str = String()
str.data = 'foo'
i = Int32()
i.data = 42
bag.write('chatter', str)
bag.write('numbers', i)
finally:
bag.close()
why don't u just use rosbag record ... if you want to some real-time calculation on the Laser data I recommend to switch to C++