Ok, we can have a go at this. Any code like this should be added in pyzo/pyzokernel. I guess the main code is best put in a new module, which is then used in interpreter.py (where the entry points for executing a file are).
I am wary of forcing a reload for each module in the user directory. Maybe we can keep track of the fileâs modified times to only reload those that changed? Letâs make a start and see how it goes.
- Almar
From: Dietrich Pescoller
Sent: 17 October 2016 18:09
To: Pyzo
Cc: ***@gmail.com
Subject: Re: [Pyzo] how to execute python magics from script
Hmm have you ever used Spyder?
The module auto loading works very well there.
1) Initially i started using Pyzo (when it both a python distro and an editor)
2) then I switched to Spyder, because of the module reloading problem. The Spyder UMR (User Module Reloader) works quite well and is something needed when you do scientific computaton
where you typicallycan not always restart the shell but you are continuously adapting, updating and changing your functions
3) than I switched back to IEP, because on the other side the debugging in Spyder is very uncomfortable.
Now since both Spyder and IEP are just editors (which I find good) one can switch easily between the two depending on what is more important. But of course one would prefer to use
always the same tool. And in my opinion (having used both as a scientific user) personally I thing IEP is perhaps the better solution.
Some feature are already present in the ipython shell like the autoreload, and this was basically the rationale behind my question.
Perhaps IEP could implement the UMR as well? If you look at how it is implemented in Spyder it is something quite simple:Â
https://github.com/spyder-ide/spyder/blob/master/spyder/utils/site/sitecustomize.py
I could contribute in this but I'm still missing the whole picture of the pyzo code. So I would have big difficulties to know where to put similar code.
Or perhaps there are other ways to achieve the same result don't know.
Bye,
Dietrich
Post by Dietrich Pescoller1) run/call a script from another script
Â
code = open(filename, ârbâ).read().decode()
exec(code)Â # look at the docs of exec for possible extra arguments
Â
Post by Dietrich Pescollermake python use changes when you edit a file
Â
This is not trivial; it would require a lot more than 2 lines :) Â though maybe there is a lib for that?
Â
The workflow in Pyzo would be to select a file as main file, so that you can execute it while working on another file, and the run the main file using Run > run main file as script, or better yet, use Ctrl+Shift+E. Running as script is important because it will restart the shell and use the latest version of all modules.
Â
Regards,
 Almar
Â
Â
From: Dietrich Pescoller
Sent: 07 October 2016 14:54
To: Pyzo
Cc: ***@gmail.com
Subject: Re: [Pyzo] how to execute python magics from script
Â
Is there another way to obtain the same result in python without using magics?
There are many use cases but at least I would like to be able at least to:
1) run/call a script from another script
  this is achieved in ipython with %run -i myFile.py
2) make python use changes when you edit a file
 this is achieved in ipython by calling
 % load_ext autoreload
 % autoreload 2
Â
Thanks,
Dietrich
Il giorno martedì 27 settembre 2016 21:52:22 UTC+2, Almar Klein ha scritto:
No, its not possible to use magics in the script. This is deliberate, since it would be invalid Python. Not sure why the use of the ipython API calls would not work. Pyzoâs IPython shell is not completely a proper IPython shell, so it might be that we donât do enough for this to be picked up somehowâŠ
Â
What is the problem that youâre trying to fix, or workflow that youâre trying to achieve? Maybe there are other ways to make it work.
Â
- Almar
Â
Â
Â
From: Dietrich Pescoller
Sent: 27 September 2016 18:22
To: Pyzo
Subject: [Pyzo] how to execute python magics from script
Â
Is there a way to execute ipython magics from script in IEP.
In particular I'm interested in startup script
I tired something like this:
from IPython import get_ipython
get_ipython().magic('load_ext autoreload')
get_ipython().magic('autoreload 2')
Â
Which works in a standard ipython console but does not work when using IEP.
Any suggestion would be apprecieated
Thanks,
Dietrich
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyzo+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Â
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyzo+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Â
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyzo+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyzo+***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.