WorldViz User Forum

WorldViz User Forum (https://forum.worldviz.com/index.php)
-   Vizard (https://forum.worldviz.com/forumdisplay.php?f=17)
-   -   Modules / Require / Include function (https://forum.worldviz.com/showthread.php?t=333)

Johannes 04-27-2005 10:18 AM

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

farshizzo 04-27-2005 10:35 AM

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.

Johannes 04-27-2005 10:44 AM

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

farshizzo 04-27-2005 10:54 AM

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.

Johannes 04-27-2005 11:12 AM

OK, thank you.
Johannes


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

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