I'll have to check that out. It looks like it would work fine for my purposes 
since I normally run from virtual envs, but could be restrictive in that the 
user site-packages isn't added.
I also found some other mentions of this:
https://bugs.python.org/issue33053https://bugs.python.org/issue13475
One idea may be, when executing "python -m", check to see if the module is 
loaded from CWD, if so then have CWD added, but if the module is not loaded 
from CWD then not have it added.

-----Original Message-----
From: Nick Timkovich <prometheus...@gmail.com>
To: Brianvanderburg2 <brianvanderbu...@aim.com>
Cc: python-ideas@python.org <python-ideas@python.org>
Sent: Mon, Feb 24, 2020 2:52 pm
Subject: Re: [Python-ideas] Control adding script path/CWD to sys.path

On Mon, Feb 24, 2020 at 11:51 AM Brianvanderburg2 via Python-ideas 
<python-ideas@python.org> wrote:

When running a python script directly, the directory of that script gets added 
to sys.path.  When running as a module "python -m", it looks like an empty 
string gets added to sys.path, which appears to result in CWD being used.

Are you familiar with the -I option for "isolated mode"? 
https://docs.python.org/3/using/cmdline.html#id2 

-I
Run Python in isolated mode. This also implies -E and -s. In isolated mode 
sys.path contains neither the script’s directory nor the user’s site-packages 
directory. All PYTHON* environment variables are ignored, too. Further 
restrictions may be imposed to prevent the user from injecting malicious code. 
New in version 3.4.

_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/SB577SR3BEJTKWEXTREYTGGAD5CNE2S5/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to