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

How to import module to service code in Python?

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

flipback gravatar image

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

Hello, everyone! I'm writing a ROS service for my robot in Python. I have one file which contains all code in arm_mover.py . 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.

/package_root
 |--/scripts
 |   |-----arm_mover.py
 |--/src
     |-----/helpers
           |--__init__.py
           |--comm.py

Thanks, for help.

edit retag flag offensive close merge delete

Comments

1

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 -0600 )edit

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

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

1 Answer

Sort by ยป oldest newest most voted
0

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

flipback gravatar image

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

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

Maybe someone has a more pretty idea.

edit flag offensive delete link more

Comments

1

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

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

Question Tools

1 follower

Stats

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

Seen: 279 times

Last updated: Oct 21 '13