tags:

views:

99

answers:

1

What happens when I reload a module in python and the new code for the module is syntactically incorrect? The reload(module) function doesn't seem to be throwing any exception. Is there any way to determine if the reload was successful or failed?

+3  A: 

The reload() command should raise a SyntaxError:

In [34]: import test
# This works fine

After making a syntax error in test.py: (changed import --> pimport)

In [35]: reload(test)
------------------------------------------------------------
   File "/home/unutbu/pybin/test.py", line 2
     pimport itertools
                     ^
SyntaxError: invalid syntax
unutbu
+1 for being faster than me at responding!
jathanism
Thanx a lot. I think I figured out my mistake. I had introduced a a simple syntax error in the middle of a function. That error didn't really stop python from reloading the module. Since I was editing in Eclipse with PyDev it showed me the error in advance and I was wondering why Python is allowing to reload the module.
Shailesh Kumar
Ah, I see. Thanks for adding this explanation.
unutbu