WorldViz User Forum  

Go Back   WorldViz User Forum > Vizard

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 04-27-2005, 10:18 AM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
Modules / Require / Include function

Developing different programs that use some of the same code I was wondering if python also has a fuction like e.g. php to include small code snippets at certain positions.

I've already used the module-idea (e.g. import graphModule and then using it with graphModule.blabla ) but it is not the same as just outsourcing part of the code.

Is there some command to do this?

Johannes
Reply With Quote
  #2  
Old 04-27-2005, 10:35 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

Python doesn't have a built-in way of doing this. You pretty much have to use the import syntax. You could try the following:
Code:
execfile('graphModule.py')
However I would recommend just using the import syntax.
Reply With Quote
  #3  
Old 04-27-2005, 10:44 AM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
Thank you for the fast answer.

Yes, execfile('graphModule.py') works. Why would you not recommend it?

Is the file called loaded from the harddrive every time I call execFile(File)?
=> slow down

Johannes
Reply With Quote
  #4  
Old 04-27-2005, 10:54 AM
farshizzo farshizzo is offline
WorldViz Team Member
 
Join Date: Mar 2003
Posts: 2,849
Hi,

I believe every time you call execfile, python will look on the hard drive for the filename. I think Python optimizes this a little by compiling the script into a .pyc file, and using that on subsequent calls. I'm not sure if Python stores the code in memory for further optimizations.

There really is no harm in doing this, I just see it as a bad workaround to simply importing the module.
Reply With Quote
  #5  
Old 04-27-2005, 11:12 AM
Johannes Johannes is offline
Member
 
Join Date: Jan 2005
Posts: 143
OK, thank you.
Johannes
Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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:40 AM.


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