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

Revision history [back]

Are you sure that code worked previously? I'm not aware of any recent changes to rospy that would have changed this behavior, but I suppose I could have missed something.

Regardless, there are a variety of functions specifically for getting names from the ROS graph in the rospy.names module. You could instead be using rospy.get_namespace() or perhaps rospy.get_name() (depending on what you are trying to do). Additionally rospy is slightly different from C++ in that you don't need a "private node handle" to be able to access private parameters. In other words, depending on what you are doing, you might not even need to get the namespace directly. You might be able to use something like rospy.get_param("~private_param1").

Are you sure that code worked previously? I'm not aware of any recent changes to rospy that would have changed this behavior, but I suppose I could have missed something.something. Also note that the KeyError being thrown is exactly what should happen if the parameter you are trying to get ("~") doesn't exist and you don't provide a default value (documentation here).

Regardless, there are a variety of functions specifically for getting names from the ROS graph in the rospy.names module. You could instead be using rospy.get_namespace() or perhaps rospy.get_name() (depending on what you are trying to do). Additionally rospy is slightly different from C++ in that you don't need a "private node handle" to be able to access private parameters. In other words, depending on what you are doing, you might not even need to get the namespace directly. You might be able to use something like rospy.get_param("~private_param1").