Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python reload function and syntactically incorrect module

Tags:

python

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?

like image 516
Shailesh Kumar Avatar asked Mar 15 '26 22:03

Shailesh Kumar


1 Answers

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
like image 66
unutbu Avatar answered Mar 18 '26 12:03

unutbu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!