Python implementation of "include"

Luke elvenson at msn.com
Sun Dec 16 14:36:39 EST 2007


Gabriel Genellina wrote:

> En Thu, 13 Dec 2007 19:53:49 -0300, <lloyd at paisite.com> escribió:
> 
>> As I understand it, import myFile and include "myFile.py" are not quite
>> the same.
>>
>> --
>> for import to work myFile.py must be in the same directory as the code
>> that calls it accessible through PYTHONPATH, whereas include
>> "../somedirectory/myFile.py" works in Karrigell, even though it is not
>> accessible through PYTHONPATH.
>>
>> -- if imported, the print
>> statement myFile.py would only run the first time through unless
>> reload(myFile) is executed in the proper place.
> 
> execfile("../somedirectory/myFile.py") does not have those problems.
> 


place your code within the module into a function, then in the calling file
just include the module using "include myFile", to get at the code you want
to use, simply call the function as "myFile.myFunction()". (obviously, drop
the quotes and use the names you made for the module and function...)



More information about the Python-list mailing list