On Monday, May 18, 2020 at 7:13:06 AM UTC-7, JokingReaper wrote:
>
> Apparently I found the problem... NEVER name a file "sage.py" in the same 
> folder of the notebooks, it will only create a conflict with the package 
> "sage" from SageMath, and think that the file "sage.py" is the package that 
> must be used... don't know if there is a work-around this to warn users or 
> if there is a way to tell the kernel to alway prioretize the file from it's 
> source folder.
>

This is a "well-known" problem in python:

http://python-notes.curiousefficiency.org/en/latest/python_concepts/import_traps.html#the-name-shadowing-trap

There is a "workaround" in python, but it's probably unworkable for other 
reasons: if you remove the empty string from sys.path, then the current 
directory is no longer part of the places where modules are searched, so 
under normal conditions, after:

import sys
sys.path.remove('')

your file sage.py would no longer be shadowing (all of!) sage. You'd have 
to find a way to ensure that this code is run before python tries to load 
sage, though.

It means, for one thing, that you should *NEVER* run a python program in an 
untrusted directory (where there may be unknown files shadowing whatever 
and/or someone may place files there unexpectedly), which can be 
complicated if a nice utility happens to be written in python. As the trick 
above shows, there are ways to harden python against this trap, but it's 
hard to do and easy to forget, so I expect it's usually neglected.

This is probably one of the most prominent tensions in python being both a 
scripting and an application language. The two functions would choose 
different priorities in features/traps like this, and here scripting has 
won ...

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/041119ca-175c-4d91-80d9-4b041cecad45%40googlegroups.com.

Reply via email to