ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

subscriber node showing error while try running

asked 2018-10-24 03:32:13 -0500

Labid52 gravatar image

updated 2018-10-24 03:33:41 -0500

gvdhoorn gravatar image

whenever I want to run the following code in http://wiki.ros.org/rospy_tutorials/T... , that is:

#!/usr/bin/env python
import rospy

from std_msgs.msg import String

def callback(data):

    rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)

def listener():

    # In ROS, nodes are uniquely named. If two nodes with the same
    # node are launched, the previous one is kicked off. The
    # anonymous=True flag means that rospy will choose a unique
    # name for our 'talker' node so that multiple talkers can
    # run simultaneously.
    rospy.init_node('listener', anonymous=True)
    rospy.Subscriber("chatter", String, callback)
    # spin() simply keeps python from exiting until this node
    #is stopped
    rospy.spin()
if __name__ == '__main__':
    listener()

I get the following error at terminal:

from: can't read /var/mail/std_msgs.msg
/home/labid52/catkin_ws/src/hello_world/script/listener.py: line 3: syntax error near unexpected token `('
/home/labid52/catkin_ws/src/hello_world/script/listener.py: line 3: `def callback(data):'
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-10-24 03:35:57 -0500

gvdhoorn gravatar image

It is very likely you have a space or an empty line before the #!/usr/bin/env python line in your script.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-10-24 03:32:13 -0500

Seen: 293 times

Last updated: Oct 24 '18