Re: [Tutor] What exactly does the three dots do? Why such as thing?

2017-08-27 Thread C W
Today, I ran into ellipsis again. This time, it is COMPLETELY different
from before.

Here is a reproducible code:

import numpy as np
import matplotlib.pyplot as plt
...
x = np.linspace(0, 1)
y = np.sin(4 * np.pi * x) * np.exp(-5 * x)
plt.title('Week cycle')
plt.xlabel('Month')
plt.ylabel('Price')
plt.plot(x, y)


If I leave out the ellipsis, plot title and label will not show. It's doing
interactive plot. How am I suppose to know ellipsis is doing interactive
plotting? No way I could have guessed.

Matplotlib documentation  explains that it
recreated itself from Matlab plots.

Is it something similar to Matlab like
>>> hold on;

That's fine! But, how many identities will ellipsis take on? How do you
experienced users deal with these ambiguities?



On Fri, Aug 11, 2017 at 9:24 PM, Steven D'Aprano 
wrote:

> On Fri, Aug 11, 2017 at 07:57:09AM -0600, Mats Wichmann wrote:
> > On 08/10/2017 05:23 PM, Alan Gauld via Tutor wrote:
> > > On 10/08/17 14:39, C W wrote:
> > >
> > >> I suppose it's just a place holder, though I don't know when I would
> use it
> > >> in my every day life.
> > >
> > > Probably never.
> > >
> > > Like most programming languages Python has a load of rarely used,
> > > obscure features. Most Python programmers never use ellipses,
> >
> > I guess what this means is when I post code snippets with some lines
> > elided for greater readability of the point being made I should not use
> > ellipses for that, as they're actually a syntactic element!   :)
>
> No, go right ahead and continue using ... for elided lines. Python 3
> makes that syntactically legal, and the fact that elided code may be
> syntactically correct is one of the reasons that was done.
>
> In Python 2, ... was just the *display* form of Ellipsis, and wasn't
> legal except in slice notation: a[...]. Python 3 made ... syntactic
> sugar for Ellipse everywhere, not just in slices, which makes:
>
> x = ...
>
> class X:
> ...
>
> perfectly legal code. (Perhaps not *meaningful* code, but that's okay.)
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What exactly does the three dots do? Why such as thing?

2017-08-11 Thread Steven D'Aprano
On Fri, Aug 11, 2017 at 07:57:09AM -0600, Mats Wichmann wrote:
> On 08/10/2017 05:23 PM, Alan Gauld via Tutor wrote:
> > On 10/08/17 14:39, C W wrote:
> > 
> >> I suppose it's just a place holder, though I don't know when I would use it
> >> in my every day life.
> > 
> > Probably never.
> > 
> > Like most programming languages Python has a load of rarely used,
> > obscure features. Most Python programmers never use ellipses,
> 
> I guess what this means is when I post code snippets with some lines
> elided for greater readability of the point being made I should not use
> ellipses for that, as they're actually a syntactic element!   :)

No, go right ahead and continue using ... for elided lines. Python 3 
makes that syntactically legal, and the fact that elided code may be 
syntactically correct is one of the reasons that was done.

In Python 2, ... was just the *display* form of Ellipsis, and wasn't 
legal except in slice notation: a[...]. Python 3 made ... syntactic 
sugar for Ellipse everywhere, not just in slices, which makes:

x = ...

class X:
...

perfectly legal code. (Perhaps not *meaningful* code, but that's okay.)


-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What exactly does the three dots do? Why such as thing?

2017-08-11 Thread Alan Gauld via Tutor
On 11/08/17 14:57, Mats Wichmann wrote:

>> obscure features. Most Python programmers never use ellipses,
> 
> I guess what this means is when I post code snippets with some lines
> elided for greater readability of the point being made I should not use
> ellipses for that, as they're actually a syntactic element!   :)

Good point, because I often do that when replying to posts

def foo():...

I certainly don't mean the ellipses to be a syntactic element!


-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What exactly does the three dots do? Why such as thing?

2017-08-11 Thread Mats Wichmann
On 08/10/2017 05:23 PM, Alan Gauld via Tutor wrote:
> On 10/08/17 14:39, C W wrote:
> 
>> I suppose it's just a place holder, though I don't know when I would use it
>> in my every day life.
> 
> Probably never.
> 
> Like most programming languages Python has a load of rarely used,
> obscure features. Most Python programmers never use ellipses,

I guess what this means is when I post code snippets with some lines
elided for greater readability of the point being made I should not use
ellipses for that, as they're actually a syntactic element!   :)

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What exactly does the three dots do? Why such as thing?

2017-08-10 Thread Alan Gauld via Tutor
On 10/08/17 14:39, C W wrote:

> I suppose it's just a place holder, though I don't know when I would use it
> in my every day life.

Probably never.

Like most programming languages Python has a load of rarely used,
obscure features. Most Python programmers never use ellipses,
metaclasses(*), the __new__() constructor, the _ variable or
even the else clause in a loop. That doesn't mean you shouldn't
look into them - they might just be the bit of magic you
need - but don't feel you need to have a use for every
bit of the language.

(*) Actually, everyone uses metaclasses, but very few define
their own!

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What exactly does the three dots do? Why such as thing?

2017-08-10 Thread C W
What's a literal? The only other time I heard about it was studying
Shakespare. ;)

I don't know what literal is. So, it won't help me to understand ellipsis,
I really thought it was that oval shaped figure.

Wiki says: "Literals are often used to initialize variables"

https://en.wikipedia.org/wiki/Literal_(computer_programming)

I suppose it's just a place holder, though I don't know when I would use it
in my every day life.

On Thu, Aug 10, 2017 at 8:47 AM, Steven D'Aprano 
wrote:

> On Wed, Aug 09, 2017 at 12:06:37PM -0400, C W wrote:
> > Dear Python experts,
> >
> > What exactly does the three dots do?
> > > aList = ...
>
> ... is literal syntax for the Ellipsis singleton object.
>
> Ellipsis was added to the language at the express request of the numpy
> developers. Although numpy is a third-party project outside of the
> standard library, it is big enough and important enough that their
> requests carry a LOT of weight with the core Python devs. Other features
> Python has that were originally added at the request of numpy include:
>
> - extended slicing with two colons obj[a:b:c]
>
> - the @ operator used by numpy for matrix multiplication.
>
> I don't know what Ellipsis is used for by numpy, but now it makes a
> convenient pseudo-pass command:
>
> class X:
> ...
>
> def func():
> ...
>
>
> > It's an ellipsis, a spot holder to later. But what data type is it:
> vector,
> > matrix?
>
> Its a singleton object. Think of it as a sibling to None and
> NotImplemented, but with optional funny syntactic sugar ... to refer to
> it.
>
> None is a special value used as "no such value", or nil or null;
>
> NotImplemented is a special value used by operator dunder methods like
> __add__ and __mul__ to mean "I can't handle this argument";
>
> Ellipsis is a special value used by numpy to mean whatever it is that
> numpy uses it to me.
>
>
> --
> Steve
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What exactly does the three dots do? Why such as thing?

2017-08-10 Thread Steven D'Aprano
On Thu, Aug 10, 2017 at 09:39:02AM -0400, C W wrote:

> What's a literal? The only other time I heard about it was studying
> Shakespare. ;)

A "literal" is syntax that creates a value, without the programmer 
needing to call a function. The syntax stands for the LITERAL value as 
shown.

For example, we write:

number = 123  # stands for literally 123

rather than:

number = int(hundreds=1, tens=2, units=3)

Examples of literals:

"Hello World!"  # a string
1.234  # a float
999  # an int
True  # bool true value
None  # the special None value


Technically, these aren't literals, but they're the moral equivalent of 
literals:

[1, 2, None, "Hello", 23]  # a list
(1, 2, 3)  # a tuple
{'key': 'value'}  # a dict


> I don't know what literal is. So, it won't help me to understand ellipsis,
> I really thought it was that oval shaped figure.

Ellipsis \El*lip"sis\ ([e^]l*l[i^]p"s[i^]s), n.; pl. Ellipses

  (Gram.) Omission; a figure of syntax, by which one or more
  words, which are obviously understood, are omitted; as,
  the virtues I admire, for, the virtues which I admire.
  [1913 Webster]

  (Printing) a printing symbol, usually three periods in a
  row (. . .), indicating the omission of some part of a
  text; -- used commonly in quotations, so as to suppress
  words not essential to the meaning. A long dash (---) and
  three asterisks (* * *) are sometimes used with the same
  meaning.


There's also an older (now obsolete) meaning of "ellipsis" as a synonym 
for "ellipse", which is an oval-shaped figure.


> Wiki says: "Literals are often used to initialize variables"

As in:

n = 0
x = 1.5



Outside of numpy, I've never seen anyone use Ellipsis (whether spelled 
by name or by three dots) except to be cute. I'm sure it has use to some 
people, otherwise it wouldn't have been added, but its pretty 
specialized.




-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] What exactly does the three dots do? Why such as thing?

2017-08-10 Thread Steven D'Aprano
On Wed, Aug 09, 2017 at 12:06:37PM -0400, C W wrote:
> Dear Python experts,
> 
> What exactly does the three dots do?
> > aList = ...

... is literal syntax for the Ellipsis singleton object.

Ellipsis was added to the language at the express request of the numpy 
developers. Although numpy is a third-party project outside of the 
standard library, it is big enough and important enough that their 
requests carry a LOT of weight with the core Python devs. Other features 
Python has that were originally added at the request of numpy include:

- extended slicing with two colons obj[a:b:c]

- the @ operator used by numpy for matrix multiplication.

I don't know what Ellipsis is used for by numpy, but now it makes a 
convenient pseudo-pass command:

class X:
...

def func():
...


> It's an ellipsis, a spot holder to later. But what data type is it: vector,
> matrix?

Its a singleton object. Think of it as a sibling to None and 
NotImplemented, but with optional funny syntactic sugar ... to refer to 
it.

None is a special value used as "no such value", or nil or null;

NotImplemented is a special value used by operator dunder methods like 
__add__ and __mul__ to mean "I can't handle this argument";

Ellipsis is a special value used by numpy to mean whatever it is that 
numpy uses it to me.


-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor