On Fri, Aug 21, 2020 at 09:35:14AM -, Gustav O wrote:
> 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
On 22/08/20 6:43 am, Serhiy Storchaka wrote:
It would have non-zero cost. There is a common idiom:
try:
from foo import bar
except ImportError:
def bar(): ...
In this case you would need to try importing foo from other locations.
I wouldn't suggest going that far.
On Fri, Aug 21, 2020, at 15:13, Gustav O wrote:
> In the beginning of the programming journey, getting a message about
> circular imports when they were testing out tkinter in a file names
> "tkinter.py" would probably not be helpful. Getting a message that
> hints that you may have
I actually didn't know that there were use cases for importing itself — thanks
for letting me know.
The best way of implementing a better error message would probably be to change
the message for when the user import itself, while it's still partially
initialized.
In the beginning of the
21.08.20 18:22, Greg Ewing пише:
> Maybe check whether the module being imported from is shadowing another
> module further along the search path and warn about that?
It would have non-zero cost. There is a common idiom:
try:
from foo import bar
except ImportError:
def
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
Great that you point that out. I have thought of are two possible solutions to
this:
1. Make the current error message clearer, but make sure that it's correct for
both cases
2. Create a special case for trying to import itself.
I personally think the second option would be superior. If
Maybe check whether the module being imported from is shadowing another
module further along the search path and warn about that?
--
Greg
___
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to
On Fri, Aug 21, 2020 at 11:40 PM Gustav O wrote:
>
> 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
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
10 matches
Mail list logo