Ask Your Question
0

dynamically create,compile and import msg files

asked 2011-06-29 04:51:42 -0500

jduewel gravatar image

updated 2011-09-03 15:35:23 -0500

kwc gravatar image

hello,

i'm trying to create and dynamically compile msg files to use them while the node is running. Somehow it works only for the first msg file which i create,compile and import. Every file which i try to import after the first one gets an import error.

Here is a very simple example of what im trying to do:

#!/usr/bin/env python
PKG = 'janus'
msgPath = "/home/jan/Desktop/Janus/trunk/janus/msg" #my Path to the msg folder

import os
import codecs
import roslib; roslib.load_manifest(PKG)

os.chdir(msgPath)

fobj = codecs.open("test"+".msg", 'w')
fobj.write("float32 buttons")
fobj.close()
exec('os.system("rosmake %s")' %PKG)
exec('from %s.msg import test' %PKG)

fobj1 = codecs.open("test1"+".msg", 'w')
fobj1.write("float32 buttons")
fobj1.close()
exec('os.system("rosmake %s")' %PKG)
exec('from %s.msg import test1' %PKG)

So why it imports the first file, but not the second? :( hope you can help me thx

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2011-06-29 05:19:01 -0500

kwc gravatar image

You need to reload the Python module. After the first call, Python has loaded 'janus' and will not go back out to disk.

http://docs.python.org/release/2.7/library/functions.html#reload

Note: in general, you have to be careful when calling reload as it can result in inconsistent modules. It should be fine if you are just fetching msg files.

edit flag offensive delete link more

Comments

Ive read the manual carefully, but i still dont know which module to reload.
jduewel gravatar image jduewel  ( 2011-06-29 11:38:44 -0500 )edit
From your code, it looks like 'janus' is the module.
kwc gravatar image kwc  ( 2011-06-29 13:48:18 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2011-06-29 04:51:42 -0500

Seen: 441 times

Last updated: Jun 29 '11