This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Error message persists when reimporting library
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: AwesomeCronk, steven.daprano, xtreak
Priority: normal Keywords:

Created on 2019-10-07 16:51 by AwesomeCronk, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pythonerror.png AwesomeCronk, 2019-10-07 16:51 example of this behavior
Messages (3)
msg354120 - (view) Author: AwesomeCronk (AwesomeCronk) Date: 2019-10-07 16:51
I am working on a hexdump library in Python 3.7.4.
Whenever an issue is triggered, the error message shows up. I can usually edit and correct the file(library), but when I reimport the library and rerun the function, it throws the same error on the same line number, even if the line was removed or commented out.
msg354121 - (view) Author: Karthikeyan Singaravelan (xtreak) * (Python committer) Date: 2019-10-07 16:58
I think this is due to str bytes concatenation error on line number 19. Editing and reimporting doesn't give you new code in repl. Try the changes in new repl after changing it in file. Python will just use unchanged code and will use line number 19 in traceback to show error which is different as file was edited.
msg354150 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2019-10-07 22:49
Importing the second and subsequent times reloads the module from the system cache. Instead, you can:

- run ``del sys.modules['hexdump']`` and then ``import hexdump``;

- call ``importlib.reload(hexdump)``; or

- restart the REPL.

Remember that reloading the module won't redefine any existing classes or instances you created from the old module, they will continue to reference the old module code until they are destroyed and recreated. So the last option (restarting the REPL) is usually the most effective. But with care, reload(hexdump) should do the trick.
History
Date User Action Args
2022-04-11 14:59:21adminsetgithub: 82580
2019-10-07 22:49:49steven.dapranosetstatus: open -> closed

nosy: + steven.daprano
messages: + msg354150

resolution: not a bug
stage: resolved
2019-10-07 16:58:59xtreaksetnosy: + xtreak
messages: + msg354121
2019-10-07 16:51:31AwesomeCronkcreate