[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Andrew Barnert via Python-ideas
On Nov 8, 2019, at 07:50, Steve Barnes wrote:, > > > I hope that his hasn’t been discussed to death in the past but I quite often > encounter cases where developers have unwittingly created a file or directory > that has a name clash with either a system import or a pip installed library > i

[Python-ideas] A bit change to create a matrix variable in Python as easy as MATLAB and Julia!

2019-11-08 Thread yejustme
In recent years, python has become very popular due to the rise of data science and machine learning. This is mainly because Python is easy to learn and has a large number of third-party libraries, thus accumulating a large number of users. When Python is applied to scientific computing, t

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Anders Hovmöller
> On 8 Nov 2019, at 07:52, Steve Barnes wrote: > >  > Hi, > > I hope that his hasn’t been discussed to death in the past but I quite often > encounter cases where developers have unwittingly created a file or directory > that has a name clash with either a system import or a pip installed

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Jonathan Fine
Hi All I think we can learn from Unix/Linux here. Like python, it has a PATH variable for finding executables. It also has a command 'which'. According to the man page DESCRIPTION which returns the pathnames of the files (or links) which would be executed in the current environment, had its arg

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Dan Sommers
On 11/8/19 10:40 AM, Jonathan Fine wrote: Hi All I think we can learn from Unix/Linux here. Like python, it has a PATH variable for finding executables. It also has a command 'which'. Python already has a "-v" option: -v Print a message each time a module is initialized, showing

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Brian Skinn
Jonathan Fine wrote: > Suppose we had a similar 'which' command in Python. It wouldn't by > itself stop things going wrong. But when they do go wrong, it might > help diagnose the problem. This thread got me thinking about something exactly along these lines. It looks like the needed information

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Anders Hovmöller
> On 8 Nov 2019, at 18:06, Dan Sommers <[email protected]> > wrote: > > On 11/8/19 10:40 AM, Jonathan Fine wrote: >> Hi All >> I think we can learn from Unix/Linux here. Like python, it has a PATH >> variable for finding executables. It also has a command 'which'. > > Python

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Andrew Barnert via Python-ideas
On Nov 8, 2019, at 18:14, Brian Skinn wrote: > > For nonbuiltins, the full path to the relevant .py is returned: > >> inspect.getfile(inspect) > 'C:\\...\\Python\\Python37\\Lib\\inspect.py' What does it do for zipimported modules, bootstrapped modules, modules distributed as a .pyc file witho

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Dan Sommers
On 11/8/19 11:28 AM, Anders Hovmöller wrote: >> On 8 Nov 2019, at 18:06, Dan Sommers <[email protected]> wrote: >> On 11/8/19 10:40 AM, Jonathan Fine wrote: >>> I think we can learn from Unix/Linux here. Like python, it has a PATH >>> variable for finding executables. It als

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Ricky Teachey
throwing this idea out there, no idea if it is practical but it might be pretty nice/easily understood syntax. could a context manager be created such that anything imported under it is guaranteed to be imported from the standard library, and produce an error otherwise? perhaps by adding a level k

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Brian Skinn
Andrew Barnert wrote: > What does it do for zipimported modules, bootstrapped modules, modules > distributed as a .pyc file without the .py source, etc., plain old .py filed > but that are > found in an unusual way (a 3.x equivalent of Apple’s 2.7 Extras directory, or > even a > custom importlib

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Brett Cannon
On Fri, Nov 8, 2019 at 10:01 AM Ricky Teachey wrote: > throwing this idea out there, no idea if it is practical but it might be > pretty nice/easily understood syntax. > > could a context manager be created such that anything imported under it is > guaranteed to be imported from the standard libr

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Anders Hovmöller
> On 8 Nov 2019, at 18:57, Dan Sommers <[email protected]> > wrote: > > On 11/8/19 11:28 AM, Anders Hovmöller wrote: > > >> On 8 Nov 2019, at 18:06, Dan Sommers <[email protected]> > >> wrote: > > >> On 11/8/19 10:40 AM, Jonathan Fine wrote: > > >>> I thi

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Andrew Barnert via Python-ideas
On Nov 8, 2019, at 18:59, Brian Skinn wrote: > > And no, I suspect it would be *quite* hard to write automated software able > to reliably assign a given module's path into those categories. It raises > basically the same set of problems as writing an automated mechanism for > _constraining_ i

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Andrew Barnert via Python-ideas
On Nov 8, 2019, at 07:50, Steve Barnes wrote: > > > I hope that his hasn’t been discussed to death in the past but I quite often > encounter cases where developers have unwittingly created a file or directory > that has a name clash with either a system import or a pip installed library > im

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread Ricky Teachey
> __import__ already has a 'level' argument. > doh! maybe "context" is better, then. > Not without frame inspection to know what import statements are in the > context manager's block. > > I don't doubt you know what you're talking about, so this is a learning question: why couldn't you do it by

[Python-ideas] Re: Suggest having a mechanism to distinguish import sources

2019-11-08 Thread MRAB
On 2019-11-08 18:09, Brett Cannon wrote: On Fri, Nov 8, 2019 at 10:01 AM Ricky Teachey > wrote: throwing this idea out there, no idea if it is practical but it might be pretty nice/easily understood syntax. could a context manager be created such that an

[Python-ideas] Re: A bit change to create a matrix variable in Python as easy as MATLAB and Julia!

2019-11-08 Thread Andrew Barnert via Python-ideas
On Nov 8, 2019, at 04:19, [email protected] wrote: > > (2) Using semicolons as a flag to make a better integration of a List-like > data type and Numpy. The Python interpreter will check whether the numpy > library is installed. If not, it will stop running and remind the user to > install it.