
21.08.20 12:35, Gustav O пише:
If a file named "tkinter.py" is created and tkinter is imported and used within the file, the following exception is raised: "AttributeError: partially initialized module 'tkinter' has no attribute 'Tk' (most likely due to a circular import)"
I've spoken to multiple beginners who got stuck on this and just couldn't figure out what was happening. Just like the error message tells us, it's due to a "circular import". In other words, we're trying to import the very file that is doing the import. To make the message easier to understand, I propose that we change the message to something that mentions that the program is trying to import itself.
I think the following would be an option: "ImportError: partially initialized module 'tkinter' can't import itself"
I can't think of any reason to import itself in a way like this, but even if there is a valid reason, the error message could probably be improved. Of course, this applies to more than just tkinter.
There is nothing wrong wrong in importing itself. Actually when you unpickle function or class defined in the same module you can import the same module.
The problem is in using partially initialized modules. And the error message has been already improved. It contains all necessary information and a hint for most common error.
And I do not think that it is a common issue. It is more likely to hide the stdlib module imported indirectly.