comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » How reload (re-import) a modified Python module through the IDL to Python bridge ?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
How reload (re-import) a modified Python module through the IDL to Python bridge ? [message #93366] Mon, 27 June 2016 06:13 Go to next message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
I want to use homemade Python modules through the IDL Python bridge.
While developing such a module (for instance by modifying it in Spyder IDE and running it in an IDLDE session, back and forth), I did not find the right way to (re)import the last modified version of the Python module, in order to use it again, from the still open IDL session.
Is there a way, from IDL or Python side, to solve that ? How does IDL locate the module specified by its name in Python.Import method ?
Thanks to anyone for any clarification.
alx.
Re: How reload (re-import) a modified Python module through the IDL to Python bridge ? [message #93367 is a reply to message #93366] Mon, 27 June 2016 06:25 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Monday, June 27, 2016 at 2:13:26 PM UTC+1, alx wrote:
> I want to use homemade Python modules through the IDL Python bridge.
> While developing such a module (for instance by modifying it in Spyder IDE and running it in an IDLDE session, back and forth), I did not find the right way to (re)import the last modified version of the Python module, in order to use it again, from the still open IDL session.
> Is there a way, from IDL or Python side, to solve that ? How does IDL locate the module specified by its name in Python.Import method ?
> Thanks to anyone for any clarification.
> alx.

Hi, if you're on the python 2.x side, I think that reload() might do the job.
https://docs.python.org/2.7/library/functions.html?highlight =reload#reload
There are some ways of doing this in 3.x using the "imp" module. No experience with that.
By the way, that's the python way. No idea if this works on the idl-python bridge! [probably not :-/]

Cheers,
Helder
Re: How reload (re-import) a modified Python module through the IDL to Python bridge ? [message #93368 is a reply to message #93367] Mon, 27 June 2016 06:51 Go to previous messageGo to next message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
Le lundi 27 juin 2016 15:25:54 UTC+2, Helder a écrit :
> On Monday, June 27, 2016 at 2:13:26 PM UTC+1, alx wrote:
>> I want to use homemade Python modules through the IDL Python bridge.
>> While developing such a module (for instance by modifying it in Spyder IDE and running it in an IDLDE session, back and forth), I did not find the right way to (re)import the last modified version of the Python module, in order to use it again, from the still open IDL session.
>> Is there a way, from IDL or Python side, to solve that ? How does IDL locate the module specified by its name in Python.Import method ?
>> Thanks to anyone for any clarification.
>> alx.
>
> Hi, if you're on the python 2.x side, I think that reload() might do the job.
> https://docs.python.org/2.7/library/functions.html?highlight =reload#reload
> There are some ways of doing this in 3.x using the "imp" module. No experience with that.
> By the way, that's the python way. No idea if this works on the idl-python bridge! [probably not :-/]
>
> Cheers,
> Helder

Well. Thanks Helder.
I am using Python 3.4. In this case, the solution (within Python) is the "importlib" module and the reload function, as you said. Spyder is likely doing that.
But my problem is that, from the IDL side, IDL still find (through the Python.Import method) the original version of the module, not the modified one. Note that the original version should have disappeared from disk (since re-edited). Same, even after a full_reset of IDL (therefore after unloading and reloading the Python dll).
There is likely something to do regarding Python caching, but I must say that I am just a Python newbie...
alx.
Re: How reload (re-import) a modified Python module through the IDL to Python bridge ? [message #93369 is a reply to message #93368] Mon, 27 June 2016 06:57 Go to previous messageGo to next message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Monday, June 27, 2016 at 2:51:26 PM UTC+1, alx wrote:
> Le lundi 27 juin 2016 15:25:54 UTC+2, Helder a écrit :
>> On Monday, June 27, 2016 at 2:13:26 PM UTC+1, alx wrote:
>>> I want to use homemade Python modules through the IDL Python bridge.
>>> While developing such a module (for instance by modifying it in Spyder IDE and running it in an IDLDE session, back and forth), I did not find the right way to (re)import the last modified version of the Python module, in order to use it again, from the still open IDL session.
>>> Is there a way, from IDL or Python side, to solve that ? How does IDL locate the module specified by its name in Python.Import method ?
>>> Thanks to anyone for any clarification.
>>> alx.
>>
>> Hi, if you're on the python 2.x side, I think that reload() might do the job.
>> https://docs.python.org/2.7/library/functions.html?highlight =reload#reload
>> There are some ways of doing this in 3.x using the "imp" module. No experience with that.
>> By the way, that's the python way. No idea if this works on the idl-python bridge! [probably not :-/]
>>
>> Cheers,
>> Helder
>
> Well. Thanks Helder.
> I am using Python 3.4. In this case, the solution (within Python) is the "importlib" module and the reload function, as you said. Spyder is likely doing that.
> But my problem is that, from the IDL side, IDL still find (through the Python.Import method) the original version of the module, not the modified one. Note that the original version should have disappeared from disk (since re-edited). Same, even after a full_reset of IDL (therefore after unloading and reloading the Python dll).
> There is likely something to do regarding Python caching, but I must say that I am just a Python newbie...
> alx.

One test could be the deleting of the .pyc file.
So if you
import myLib
then you're creating a file called myLib.pyc.
Try deleting this when you update the library...

Cheers,
Helder
Re: How reload (re-import) a modified Python module through the IDL to Python bridge ? [message #93370 is a reply to message #93369] Mon, 27 June 2016 07:14 Go to previous messageGo to next message
lecacheux.alain is currently offline  lecacheux.alain
Messages: 325
Registered: January 2008
Senior Member
Le lundi 27 juin 2016 15:57:54 UTC+2, Helder a écrit :
> On Monday, June 27, 2016 at 2:51:26 PM UTC+1, alx wrote:
>> Le lundi 27 juin 2016 15:25:54 UTC+2, Helder a écrit :
>>> On Monday, June 27, 2016 at 2:13:26 PM UTC+1, alx wrote:
>>>> I want to use homemade Python modules through the IDL Python bridge.
>>>> While developing such a module (for instance by modifying it in Spyder IDE and running it in an IDLDE session, back and forth), I did not find the right way to (re)import the last modified version of the Python module, in order to use it again, from the still open IDL session.
>>>> Is there a way, from IDL or Python side, to solve that ? How does IDL locate the module specified by its name in Python.Import method ?
>>>> Thanks to anyone for any clarification.
>>>> alx.
>>>
>>> Hi, if you're on the python 2.x side, I think that reload() might do the job.
>>> https://docs.python.org/2.7/library/functions.html?highlight =reload#reload
>>> There are some ways of doing this in 3.x using the "imp" module. No experience with that.
>>> By the way, that's the python way. No idea if this works on the idl-python bridge! [probably not :-/]
>>>
>>> Cheers,
>>> Helder
>>
>> Well. Thanks Helder.
>> I am using Python 3.4. In this case, the solution (within Python) is the "importlib" module and the reload function, as you said. Spyder is likely doing that.
>> But my problem is that, from the IDL side, IDL still find (through the Python.Import method) the original version of the module, not the modified one. Note that the original version should have disappeared from disk (since re-edited). Same, even after a full_reset of IDL (therefore after unloading and reloading the Python dll).
>> There is likely something to do regarding Python caching, but I must say that I am just a Python newbie...
>> alx.
>
> One test could be the deleting of the .pyc file.
> So if you
> import myLib
> then you're creating a file called myLib.pyc.
> Try deleting this when you update the library...
>
> Cheers,
> Helder

That might indeed be the trick.
But problem: where is this file created ? I cannot find it.
And how IDL could find it ?
Re: How reload (re-import) a modified Python module through the IDL to Python bridge ? [message #93371 is a reply to message #93370] Mon, 27 June 2016 08:04 Go to previous message
Helder Marchetto is currently offline  Helder Marchetto
Messages: 520
Registered: November 2011
Senior Member
On Monday, June 27, 2016 at 3:14:47 PM UTC+1, alx wrote:
> Le lundi 27 juin 2016 15:57:54 UTC+2, Helder a écrit :
>> On Monday, June 27, 2016 at 2:51:26 PM UTC+1, alx wrote:
>>> Le lundi 27 juin 2016 15:25:54 UTC+2, Helder a écrit :
>>>> On Monday, June 27, 2016 at 2:13:26 PM UTC+1, alx wrote:
>>>> > I want to use homemade Python modules through the IDL Python bridge.
>>>> > While developing such a module (for instance by modifying it in Spyder IDE and running it in an IDLDE session, back and forth), I did not find the right way to (re)import the last modified version of the Python module, in order to use it again, from the still open IDL session.
>>>> > Is there a way, from IDL or Python side, to solve that ? How does IDL locate the module specified by its name in Python.Import method ?
>>>> > Thanks to anyone for any clarification.
>>>> > alx.
>>>>
>>>> Hi, if you're on the python 2.x side, I think that reload() might do the job.
>>>> https://docs.python.org/2.7/library/functions.html?highlight =reload#reload
>>>> There are some ways of doing this in 3.x using the "imp" module. No experience with that.
>>>> By the way, that's the python way. No idea if this works on the idl-python bridge! [probably not :-/]
>>>>
>>>> Cheers,
>>>> Helder
>>>
>>> Well. Thanks Helder.
>>> I am using Python 3.4. In this case, the solution (within Python) is the "importlib" module and the reload function, as you said. Spyder is likely doing that.
>>> But my problem is that, from the IDL side, IDL still find (through the Python.Import method) the original version of the module, not the modified one. Note that the original version should have disappeared from disk (since re-edited). Same, even after a full_reset of IDL (therefore after unloading and reloading the Python dll).
>>> There is likely something to do regarding Python caching, but I must say that I am just a Python newbie...
>>> alx.
>>
>> One test could be the deleting of the .pyc file.
>> So if you
>> import myLib
>> then you're creating a file called myLib.pyc.
>> Try deleting this when you update the library...
>>
>> Cheers,
>> Helder
>
> That might indeed be the trick.
> But problem: where is this file created ? I cannot find it.
> And how IDL could find it ?

So I'm not that much of a Python expert. But here is what I tried:
I made a file named 'testMyPython.py' containing:

def testMyPython():
print 'here I am'

and saved it in: 'c:\pythonTests\'
I then went to the iPython command line and typed:
cd 'c:\pythonTests'
import testMyPython
testMyPython.testMyPython()

and I get indeed:
here I am

Meanwhile in the folder c:\pythonTests I now have:
testMyPython.py
testMyPython.pyc

Does this make sense to you?

Cheers,
Helder
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: ENVI_DOIT, 'MNF_DOIT' from previous noise statistics?
Next Topic: How to use mpfitfun.pro for fitting?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:22:03 PDT 2025

Total time taken to generate the page: 0.00495 seconds