Discussion:
[Pyzo] how to execute python magics from script
Dietrich Pescoller
2016-09-27 16:22:14 UTC
Permalink
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.
Almar Klein
2016-09-27 19:52:21 UTC
Permalink
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
--
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.
Dietrich Pescoller
2016-09-28 07:45:49 UTC
Permalink
Thanks, understand and make sense!

For instance I would like to have the

% load_ext autoreload

% autoreload 2

called automatically whenever I start/restart an ipython shell.

Another use case is to call other script from one script emulating the run
magic


% run myScript.py

or

% run -i myScript.py


Buy

Dietrich
Post by Almar Klein
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 <javascript:>
*Sent: *27 September 2016 18:22
*To: *Pyzo <javascript:>
*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
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
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.
Dietrich Pescoller
2016-10-07 12:51:41 UTC
Permalink
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
Post by Almar Klein
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 <javascript:>
*Sent: *27 September 2016 18:22
*To: *Pyzo <javascript:>
*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
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
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.
Dietrich Pescoller
2016-10-07 12:54:12 UTC
Permalink
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
Post by Almar Klein
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 <javascript:>
*Sent: *27 September 2016 18:22
*To: *Pyzo <javascript:>
*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
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
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.
a***@gmail.com
2016-10-08 15:56:08 UTC
Permalink
Post by Dietrich Pescoller
1) 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 Pescoller
make 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
--
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.
Dietrich Pescoller
2016-10-17 16:09:45 UTC
Permalink
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 a***@gmail.com
Post by Dietrich Pescoller
1) 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 Pescoller
make 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 <javascript:>
*Sent: *07 October 2016 14:54
*To: *Pyzo <javascript:>
*Subject: *Re: [Pyzo] how to execute python magics from script
Is there another way to obtain the same result in python without using
magics?
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
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
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
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
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.
a***@gmail.com
2016-10-25 08:40:38 UTC
Permalink
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 Pescoller
1) 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 Pescoller
make 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.
d***@microgate.it
2017-01-27 11:34:56 UTC
Permalink
Post by a***@gmail.com
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
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 Pescoller
1) 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 Pescoller
make 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
Subject: Re: [Pyzo] how to execute python magics from script
 
Is there another way to obtain the same result in python without using magics?
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
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
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.
For more options, visit https://groups.google.com/d/optout.
 
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
For more options, visit https://groups.google.com/d/optout.
 
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
For more options, visit https://groups.google.com/d/optout.
 
Hi I did some experimenting on this.
I noticed that UMR is not as powerful as %autoreload.
Could this be a possible way?
https://www.keybits.net/post/configure-autoreload-for-ipython/
How to integrate it in IEP?
--
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.
a***@gmail.com
2017-01-27 12:34:06 UTC
Permalink
What happens in Pyzo if you do as that post says?

From: ***@microgate.it
Sent: 27 January 2017 12:34
To: Pyzo
Cc: ***@gmail.com
Subject: Re: [Pyzo] how to execute python magics from script
Post by a***@gmail.com
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
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 Pescoller
1) 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 Pescoller
make 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
Subject: Re: [Pyzo] how to execute python magics from script
 
Is there another way to obtain the same result in python without using magics?
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
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
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.
For more options, visit https://groups.google.com/d/optout.
 
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
For more options, visit https://groups.google.com/d/optout.
 
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
For more options, visit https://groups.google.com/d/optout.
 
Hi I did some experimenting on this.
I noticed that UMR is not as powerful as %autoreload.
Could this be a possible way?
https://www.keybits.net/post/configure-autoreload-for-ipython/
How to integrate it in IEP?
--
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.
d***@microgate.it
2017-01-27 13:02:44 UTC
Permalink
Post by a***@gmail.com
What happens in Pyzo if you do as that post says?
 
Sent: 27 January 2017 12:34
To: Pyzo
Subject: Re: [Pyzo] how to execute python magics from script
 
Post by a***@gmail.com
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
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 Pescoller
1) 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 Pescoller
make 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
Subject: Re: [Pyzo] how to execute python magics from script
 
Is there another way to obtain the same result in python without using magics?
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
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
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.
For more options, visit https://groups.google.com/d/optout.
 
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
For more options, visit https://groups.google.com/d/optout.
 
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
For more options, visit https://groups.google.com/d/optout.
 
 
Hi I did some experimenting on this.
I noticed that UMR is not as powerful as %autoreload.
Could this be a possible way?
https://www.keybits.net/post/configure-autoreload-for-ipython/
How to integrate it in IEP?
 
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
For more options, visit https://groups.google.com/d/optout.
 
It seems it has no effect...
If instead I run the IPython (same path) outside pyze it works as expected
--
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.
d***@microgate.it
2017-01-30 19:49:33 UTC
Permalink
Post by a***@gmail.com
What happens in Pyzo if you do as that post says?
 
Sent: 27 January 2017 12:34
To: Pyzo
Subject: Re: [Pyzo] how to execute python magics from script
 
Post by a***@gmail.com
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
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 Pescoller
1) 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 Pescoller
make 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
Subject: Re: [Pyzo] how to execute python magics from script
 
Is there another way to obtain the same result in python without using magics?
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
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
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.
For more options, visit https://groups.google.com/d/optout.
 
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
For more options, visit https://groups.google.com/d/optout.
 
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
For more options, visit https://groups.google.com/d/optout.
 
 
Hi I did some experimenting on this.
I noticed that UMR is not as powerful as %autoreload.
Could this be a possible way?
https://www.keybits.net/post/configure-autoreload-for-ipython/
How to integrate it in IEP?
 
--
You received this message because you are subscribed to the Google Groups "Pyzo" group.
For more options, visit https://groups.google.com/d/optout.
 
... continuning working finally I got it to working... the solution was easy maybe you did not really got what I was looking for.

1) I put
%load_ext autoreload
%autoreload 2
in the "Code to run at startup" section of the shell configuration (there the magics are working/accepted)
2) I added a way to run the script as "run -i" see
https://github.com/pyzo/pyzo/compare/master...Diti24:patch-1

It would be nice to consider these too as a simple option for the user and become part of IEP
--
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.
Loading...