WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-16-2003, 12:53 PM
FlyingWren FlyingWren is offline
Member
 
Join Date: Mar 2003
Location: Fargo, North Dakota, USA
Posts: 48
Working w/ multiple scripts

I have a main .py script and a modular .py script that contains a class I have been developing. While working, I have both python files loaded in Vizard's editor, and the main file imports the modular one.

Sometimes it seems that when I make changes in my modular file, the main python file doesn't immediately recognize them. For instance, if I add a data member called "speed' to a class in the modular file and then try to refer to the 'speed' variable in the main script, I get a "hey, the speed variable doesn't exist!"-type error.

Reloading both files in the Vizard editor gets it to work, though - it's as if the scripts gets recompiled/rechecked so that things work again.

But surely there is a better way to do this than reloading the scripts every time I make a change, isn't there?
Reply With Quote
  #2  
Old 10-16-2003, 01:01 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
I have the same exact problem too. The reason is that when you type "import SomeModule", python checks if that module is already imported and ignores it if it is. So even if you make a change to it python will see that it has been already imported and won't do it again. The easiest way to get around this is to do the following instead of importing it:
Code:
try:
    reload(MyModule)
except:
    import MyModule
The reload command forces python to re-import the module, so new changes will take affect.
Reply With Quote
  #3  
Old 10-16-2003, 01:19 PM
FlyingWren FlyingWren is offline
Member
 
Join Date: Mar 2003
Location: Fargo, North Dakota, USA
Posts: 48
Will that same code still work if I am using
from MyModule import *

instead of just
import MyModule

or does it need a slightly different syntax?

Last edited by FlyingWren; 10-16-2003 at 01:46 PM.
Reply With Quote
  #4  
Old 10-16-2003, 02:05 PM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
It will need different syntax. The following should work:
Code:
import MyModule
reload(MyModule)
from MyModule import *
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 06:21 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Copyright 2002-2023 WorldViz LLC