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

How to import module to service code in Python?

asked 2013-10-16 06:46:11 -0500

flipback gravatar image

updated 2013-10-16 06:51:12 -0500

Hello, everyone! I'm writing a ROS service for my robot in Python. I have one file which contains all code in . The code has become too big and I need to replace a part to another module helpers.comm. But I don't understand how I must import my new module to the main script. Lines like 'import helpers.comm' or 'import package_name.helpers.comm' don't work.

 |   |

Thanks, for help.

edit retag flag offensive close merge delete



You got that `import roslib; roslib.load_manifest('my_package')` line in your script?

felix k gravatar image felix k  ( 2013-10-17 01:35:55 -0500 )edit

At first not, but I tried it out. It didn't help =(

flipback gravatar image flipback  ( 2013-10-21 04:15:09 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2013-10-21 04:50:29 -0500

flipback gravatar image

I have found a decision by myself. But it's not so elegant:

path = os.path.dirname(__file__) + "/../src/"

Maybe someone has a more pretty idea.

edit flag offensive delete link more



You could add imports for the needed classes/... in the file, but again that is now a clean way

makokal gravatar image makokal  ( 2013-10-21 05:28:56 -0500 )edit

Question Tools

1 follower


Asked: 2013-10-16 06:46:11 -0500

Seen: 236 times

Last updated: Oct 21 '13