Discussion:
[Pyzo] Imported file is not updated
Valerio
2017-11-05 11:50:21 UTC
Permalink
Hello. I am experiencing a problem with the new version of Pyzo (4.x.x).

Let's say that I have a file called "example" with the following function

def tryFun():

print("Hello")


then another "main" file in the same directory, I have:


import example

example.tryFun()


when I execute this file, I obtain "Hello" as expected. However if now I
change the first file to


def tryFun():

print("why?")


and execute the main file again, the imported file is not updated, and thus
I will still have "Hello" on the console.

I think this shouldn't be the expected behavior: if I import example again,
I wish it to be reloaded in the kernel. This may lead to unexpected bugs.

Of course, reloading the shell solves this, but I shouldn't reload the
shell every time I change one of the imported files!


Finally, this was working on the previous version of Pyzo.


Any help is appreciated
--
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
2017-11-05 13:25:48 UTC
Permalink
I can see how an auto-reload feature would be convenient during
development, but Pyzo does not have it, by design.
Post by Valerio
this was working on the previous version of Pyzo.
I don't think it was. Executing as a script should help in cases like
this, as it also restarts the kernel.
Post by Valerio
This may lead to unexpected bugs.
Since the current behavior is the default of Python, I think that
automatically reloading modules could lead to unexpected bugs; some modules
leave traces and importing them twice could break things.

If you really would like to reload on a normal run, remove the module in
question from sys.modules. E.g. in your main script do
"sys.modules.pop('example')" right before "import example".

Regards,
  Almar
Post by Valerio
Hello. I am experiencing a problem with the new version of Pyzo (4.x.x).
Let's say that I have a file called "example" with the following function
    print("Hello")
import example
example.tryFun()
when I execute this file, I obtain "Hello" as expected. However if now
I change the first file to
    print("why?")
and execute the main file again, the imported file is not updated, and
thus I will still have "Hello" on the console.
I think this shouldn't be the expected behavior: if I import example
again, I wish it to be reloaded in the kernel. This may lead to
unexpected bugs.
Of course, reloading the shell solves this, but I shouldn't reload the
shell every time I change one of the imported files!
Finally, this was working on the previous version of Pyzo.
Any help is appreciated
--
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
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.
Valerio
2017-11-05 14:17:46 UTC
Permalink
Hello Almar, thank you for the quick reply.
You pointed me to the right direction. In the past I was indeed using
"execute file as script".

To whoever is reading, on top of each of these "main" scripts (those that
calls other intenal modules) I have the following piece of code

import os, sys, inspect
src_dir = os.path.dirname(inspect.getfile(inspect.currentframe()))
lib_dir = os.path.abspath(os.path.join(src_dir, '../lib'))
os.chdir(src_dir)
sys.path.insert(0, lib_dir)

which will basically include the folder the script is in in the path, so
that it can find the other files loaded from this as a module.

Btw I use Pyzo since years (when it was IEP) and I really appreciate your
work. Thanks!
Post by Almar Klein
I can see how an auto-reload feature would be convenient during
development, but Pyzo does not have it, by design.
Post by Valerio
this was working on the previous version of Pyzo.
I don't think it was. Executing as a script should help in cases like
this, as it also restarts the kernel.
Post by Valerio
This may lead to unexpected bugs.
Since the current behavior is the default of Python, I think that
automatically reloading modules could lead to unexpected bugs; some modules
leave traces and importing them twice could break things.
If you really would like to reload on a normal run, remove the module in
question from sys.modules. E.g. in your main script do
"sys.modules.pop('example')" right before "import example".
Regards,
Almar
Post by Valerio
Hello. I am experiencing a problem with the new version of Pyzo (4.x.x).
Let's say that I have a file called "example" with the following
function
Post by Valerio
print("Hello")
import example
example.tryFun()
when I execute this file, I obtain "Hello" as expected. However if now
I change the first file to
print("why?")
and execute the main file again, the imported file is not updated, and
thus I will still have "Hello" on the console.
I think this shouldn't be the expected behavior: if I import example
again, I wish it to be reloaded in the kernel. This may lead to
unexpected bugs.
Of course, reloading the shell solves this, but I shouldn't reload the
shell every time I change one of the imported files!
Finally, this was working on the previous version of Pyzo.
Any help is appreciated
--
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
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.
Loading...