Re: Case-insensitive string equality

2017-09-05 Thread Stefan Behnel
Steve D'Aprano schrieb am 02.09.2017 um 02:31:
> - the German eszett, ß, which has two official[1] uppercase forms: 'SS'
> and an uppercase eszett

I wonder if there is an equivalent to Godwin's Law with respect to
character case related discussions and the German ß.

Stefan

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Case-insensitive string equality

2017-09-05 Thread Chris Angelico
On Tue, Sep 5, 2017 at 6:05 PM, Stefan Behnel  wrote:
> Steve D'Aprano schrieb am 02.09.2017 um 02:31:
>> - the German eszett, ß, which has two official[1] uppercase forms: 'SS'
>> and an uppercase eszett
>
> I wonder if there is an equivalent to Godwin's Law with respect to
> character case related discussions and the German ß.

Given that it's such a useful test case, I think it's inevitable (the
first part of Godwin's Law), but not a conversation killer (the second
part, and not (AFAIK) part of the original statement). Either that, or
the Turkish Iı/İi.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


How do I find what kind of exception is thrown.

2017-09-05 Thread Antoon Pardon
Python 2.6.4 on a solaris box.

I have a program in which all kind of excptions can be thrown and caugth.
The main program is something like below:

try:
do_stuff
except Exception:
log unexpected trouble

Now I found the following in the logs: [Errno 131] Connection reset by peer

This is a problem I would like to catch earlier however I have no idea what
exception I would have to catch in order to treat this case.

-- 
Antoon Pardon

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I find what kind of exception is thrown.

2017-09-05 Thread David Palao
Hi,
It looks to me like an OSError, can it be?

Best

2017-09-05 10:50 GMT+02:00 Antoon Pardon :
> Python 2.6.4 on a solaris box.
>
> I have a program in which all kind of excptions can be thrown and caugth.
> The main program is something like below:
>
> try:
> do_stuff
> except Exception:
> log unexpected trouble
>
> Now I found the following in the logs: [Errno 131] Connection reset by peer
>
> This is a problem I would like to catch earlier however I have no idea what
> exception I would have to catch in order to treat this case.
>
> --
> Antoon Pardon
>
> --
> https://mail.python.org/mailman/listinfo/python-list
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I find what kind of exception is thrown.

2017-09-05 Thread Peter Otten
Antoon Pardon wrote:

> Python 2.6.4 on a solaris box.
> 
> I have a program in which all kind of excptions can be thrown and caugth.
> The main program is something like below:
> 
> try:
> do_stuff
> except Exception:
> log unexpected trouble
> 
> Now I found the following in the logs: [Errno 131] Connection reset by
> peer
> 
> This is a problem I would like to catch earlier however I have no idea
> what exception I would have to catch in order to treat this case.
 
The logging package in the stdlib provides a way to include the traceback 
into the logfile:

$ cat log_exc.py
import logging

def do_stuff():
1/0

logger = logging.getLogger()
logging.basicConfig(filename="tmp.log")

try:
do_stuff()
except Exception:
   logger.exception("unexpected trouble")
$ python3 log_exc.py 
$ cat tmp.log
ERROR:root:unexpected trouble
Traceback (most recent call last):
  File "log_exc.py", line 10, in 
do_stuff()
  File "log_exc.py", line 4, in do_stuff
1/0
ZeroDivisionError: division by zero
$ 


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I find what kind of exception is thrown.

2017-09-05 Thread Cameron Simpson

On 05Sep2017 19:44, Cameron Simpson  wrote:
Almost anything which says "Errno ..." is almost always an OSError (or an 
IOError as I found the other day). I try to be quite picky about these. So for 
example:


Oh yes, and on a UNIX host such as Solaris the command "man 2 intro" will 
normally show you the intro to section 2 (system calls) and include a listing 
of all the errno values and their meanings.


You can probably deduce the system call from the python stack trace, so if it 
is, say, read, then "man 2 read" should include the relevant error codes and 
their cuasing circumstances.


Cheers,
Cameron Simpson  (formerly c...@zip.com.au)
--
https://mail.python.org/mailman/listinfo/python-list


Re: How do I find what kind of exception is thrown.

2017-09-05 Thread Cameron Simpson

On 05Sep2017 10:50, Antoon Pardon  wrote:

Python 2.6.4 on a solaris box.

I have a program in which all kind of excptions can be thrown and caugth.
The main program is something like below:

try:
   do_stuff
except Exception:
   log unexpected trouble

Now I found the following in the logs: [Errno 131] Connection reset by peer

This is a problem I would like to catch earlier however I have no idea what
exception I would have to catch in order to treat this case.


Almost anything which says "Errno ..." is almost always an OSError (or an 
IOError as I found the other day). I try to be quite picky about these. So for 
example:


 try:
   fp = open(filename)
 except OSError as e:
   if e.errno == errno.ENOENT:
 # file missing
 ... act as if the file were empty ...
   else:
 # other badness - let the exception escape
 raise

Cheers,
Cameron Simpson  (formerly c...@zip.com.au)
--
https://mail.python.org/mailman/listinfo/python-list


Re: How do I find what kind of exception is thrown.

2017-09-05 Thread Steve D'Aprano
On Tue, 5 Sep 2017 06:50 pm, Antoon Pardon wrote:

> Python 2.6.4 on a solaris box.
> 
> I have a program in which all kind of excptions can be thrown and caugth.
> The main program is something like below:
> 
> try:
> do_stuff
> except Exception:
> log unexpected trouble
> 
> Now I found the following in the logs: [Errno 131] Connection reset by peer
> 
> This is a problem I would like to catch earlier however I have no idea what
> exception I would have to catch in order to treat this case.


try:
do_stuff
except Exception as err:
print err, type(err)



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


How to get values for skos/note, skos/notation and label in N-Triples

2017-09-05 Thread David Shi via Python-list
 "Baginton E04009817"@en 
. 
 "Live" 
. 
 "E04009817" .

Are there any hello world examples?
Regards,
David
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Gregory Ewing

Steve D'Aprano wrote:

The third entity is the reference linking the name to the object (the arrow).
This isn't a runtime value in Python, nor is it a compile time entity that
exists in source code. It is pure implementation, and as such, exists outside
of the Python domain.


The fact that there is a connection between the name and the
object is very much part of Python's abstract semantics.

There are different ways to implement that connection, but
*any* implementation of Python has to include *some*
representation of it.

There are also different words that can be used to describe
it. You can say that names are bound to objects, or that
names refer to objects, or that names hold references to
objects. These are all equally good ways of talking about
the exact same abstract concept.

To me this argument about whether Python has references
or not is like an American person saying that cars have
hoods, and a British person saying he's wrong, hoods
are an implementation detail and cars actually have
bonnets instead.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Ben Bacarisse
Rustom Mody  writes:

> On Tuesday, September 5, 2017 at 1:44:24 AM UTC+5:30, Ben Bacarisse wrote:
>> Rustom Mody  writes:
>> 
>> > Here is some code I (tried) to write in class the other day
>> >
>> > The basic problem is of generating combinations
>> 
>> > Now thats neat as far as it goes but combinations are fundamentally sets
>> > not lists
>> >
>> > So I thought python would do a better job
>> > I tried translating it to python and sets but it turned out more annoying 
>> > than
>> > helpful
>> > Can someone improve it??
>> >
>> > The straightforward translation of the above
>> > Which is ok so far
>> >
>> >
>> > def c(n,r):
>> > if r == 0:
>> > return [[]]
>> > elif len(n) == 0:
>> > return []
>> > else:
>> > return [[n[0]] + l for l in c(n[1:],r-1)] + c(n[1:],r)
>> >
>> >
>> > Now to go from returning list of lists to set of sets:
>> 
>> def cs(n, r):
>> if r == 0:
>> return [set()]
>> elif len(n) == 0:
>> return []
>> else:
>> return [set([n[0]]) | l for l in cs(n[1:], r-1)] + cs(n[1:], r)
>> 
>> ?
>> 
>> It's not so neat if you also want n to be a set rather than a list
>> because the set equivalents of n[0] and n[1:] are a but more complex but
>> it's not that bad:
>> 
>> def css(n,r):
>> if r == 0:
>> return [set()]
>> elif len(n) == 0:
>> return []
>> else:
>> rest = n.copy()
>> e = rest.pop()
>> return [set([e]) | l for l in css(rest, r-1)] + css(rest, r)
>
> Trying out your code Ben…
>
 css({1,2,3,4}, 2)
> [set([1, 2]), set([1, 3]), set([1, 4]), set([2, 3]), set([2, 4]), set([3, 4])]
>
 type(css({1,2,3,4}, 2))
> 
>
> Whereas with the cs I earlier gave:
 cs(frozenset([1,2,3,4]), 2)
> frozenset([frozenset([2, 4]), frozenset([3, 4]), frozenset([2, 3]),
> frozenset([1, 3]), frozenset([1, 2]), frozenset([1, 4])])

If you want a (frozen) sets of sets I'd just the code to

def css(n, r):
if r == 0:
return frozenset({frozenset()})
elif len(n) == 0:
return frozenset()
else:
rest = set(n)
e = rest.pop()
return frozenset([frozenset([e])
  | l for l in list(css(rest, r-1))]) | css(rest, r)

>>> css(frozenset({1,2,3,4}), 2)
frozenset({frozenset({2, 4}), frozenset({3, 4}), frozenset({2, 3}),
frozenset({1, 3}), frozenset({1, 2}), frozenset({1, 4})})

The switch from lists (using +) and frozen sets using | is the most
obvious change, but if the top-level argument might itself be a
frozenset then the copy must be changed to a set constructor so that pop
will work.


-- 
Ben.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get values for skos/note, skos/notation and label in N-Triples

2017-09-05 Thread Rhodri James

On 05/09/17 10:31, David Shi via Python-list wrote:

 "Baginton E04009817"@en 
.  
"Live" . 
 "E04009817" .

Are there any hello world examples?


Examples of what?  You really must explain yourself clearly or we cannot 
help you.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Gregory Ewing

Steve D'Aprano wrote:

On Tue, 5 Sep 2017 02:51 am, Stefan Ram wrote:

>

 I am assuming that there are two argument passing mechanismss
 in the languages mentioned by me (C, C++, VBA, C#, Java,
 JavaScript, and Python):

- pass by aliassing (reference)
- pass "as if by assignment"


That assumption is wrong.


How is it wrong? What parameter passing mechanism in any
of those languages is not either by aliasing or by
assignment?

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Gregory Ewing

Dennis Lee Bieber wrote:

Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference
semantics, in that the definition of a function declares how the
argument(s) are passed.


Well, sort of. In Pascal and Modula, and also VB I think,
parameters are the only things that can be declared as having
reference semantics, whereas references in C++ are first-class
things that can be stored in any variable.


I don't have Java textbooks locally (in storage 15 miles away) but from
what I recall, it too has the complication of splitting between "simple
types" and "reference types" ("boxed" I believe is the term used in books).
The default passing mechanism would be similar to the description of C#
("boxed" types being implicit copies of references allowing mutation
in-place, but assignment to the parameter itself has no effect on the
caller). I suspect it too has some means to explicitly produce a
by-reference parameter.


No, Java doesn't have by-reference parameters, which can be
annoying at times when combined with the fact that it doesn't
have anything like Python's easy tuple returning and unpacking.

--
Greg

--
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Rustom Mody
On Tuesday, September 5, 2017 at 6:42:07 PM UTC+5:30, Gregory Ewing wrote:
> Steve D'Aprano wrote:
> > The third entity is the reference linking the name to the object (the 
> > arrow).
> > This isn't a runtime value in Python, nor is it a compile time entity that
> > exists in source code. It is pure implementation, and as such, exists 
> > outside
> > of the Python domain.
> 
> The fact that there is a connection between the name and the
> object is very much part of Python's abstract semantics.
> 
> There are different ways to implement that connection, but
> *any* implementation of Python has to include *some*
> representation of it.
> 
> There are also different words that can be used to describe
> it. You can say that names are bound to objects, or that
> names refer to objects, or that names hold references to
> objects. These are all equally good ways of talking about
> the exact same abstract concept.
> 
> To me this argument about whether Python has references
> or not is like an American person saying that cars have
> hoods, and a British person saying he's wrong, hoods
> are an implementation detail and cars actually have
> bonnets instead.

Also called playing humpty-dumpty

I believe there is a germ of value behind all this empty polemics 
There are 3 equivalence relations:
1. == — mathematical, too coarse to understand nuances of python semantics
2. is — machine representation, too fine to be useful
3. graph (or topological) equality which experienced pythonistas have 
internalized 
in understanding when two data structures are same or different
[Roughly Anton's diagrams that are beyond my drawing capability!]


And yet pythonistas need that to understand python data structures

>>> a = [1,2]
>>> b = [a,a]
>>> c = [[1,2],[1,2]]
>>> b == c
True
>>> b is c
False
>>> p = [1,2]
>>> q = [p,p]
>>> r = [[1,2],[1,2]]
>>> q == r
True
>>> q is r
False
>>> b == q
True
>>> b == r
True
>>> b is q
False
>>> b is r
False

Now the pythonista understands that b and c may be math-= but have different 
structure
Whereas b is graph-equal to q
And c is graph-equal to r

However there is no available operation to show/see that distinction

The trouble is that graph-isomorphism is NP-complete so the crucial operation
cannot be reasonably implemented

Let the endless threads continue 😈
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Rustom Mody
On Tuesday, September 5, 2017 at 6:59:11 PM UTC+5:30, Ben Bacarisse wrote:
> Rustom Mody  writes:
> 
> > On Tuesday, September 5, 2017 at 1:44:24 AM UTC+5:30, Ben Bacarisse wrote:
> >> Rustom Mody  writes:
> >> 
> >> > Here is some code I (tried) to write in class the other day
> >> >
> >> > The basic problem is of generating combinations
> >> 
> >> > Now thats neat as far as it goes but combinations are fundamentally sets
> >> > not lists
> >> >
> >> > So I thought python would do a better job
> >> > I tried translating it to python and sets but it turned out more 
> >> > annoying than
> >> > helpful
> >> > Can someone improve it??
> >> >
> >> > The straightforward translation of the above
> >> > Which is ok so far
> >> >
> >> >
> >> > def c(n,r):
> >> > if r == 0:
> >> > return [[]]
> >> > elif len(n) == 0:
> >> > return []
> >> > else:
> >> > return [[n[0]] + l for l in c(n[1:],r-1)] + c(n[1:],r)
> >> >
> >> >
> >> > Now to go from returning list of lists to set of sets:
> >> 
> >> def cs(n, r):
> >> if r == 0:
> >> return [set()]
> >> elif len(n) == 0:
> >> return []
> >> else:
> >> return [set([n[0]]) | l for l in cs(n[1:], r-1)] + cs(n[1:], r)
> >> 
> >> ?
> >> 
> >> It's not so neat if you also want n to be a set rather than a list
> >> because the set equivalents of n[0] and n[1:] are a but more complex but
> >> it's not that bad:
> >> 
> >> def css(n,r):
> >> if r == 0:
> >> return [set()]
> >> elif len(n) == 0:
> >> return []
> >> else:
> >> rest = n.copy()
> >> e = rest.pop()
> >> return [set([e]) | l for l in css(rest, r-1)] + css(rest, r)
> >
> > Trying out your code Ben…
> >
>  css({1,2,3,4}, 2)
> > [set([1, 2]), set([1, 3]), set([1, 4]), set([2, 3]), set([2, 4]), set([3, 
> > 4])]
> >
>  type(css({1,2,3,4}, 2))
> > 
> >
> > Whereas with the cs I earlier gave:
>  cs(frozenset([1,2,3,4]), 2)
> > frozenset([frozenset([2, 4]), frozenset([3, 4]), frozenset([2, 3]),
> > frozenset([1, 3]), frozenset([1, 2]), frozenset([1, 4])])
> 
> If you want a (frozen) sets of sets I'd just the code to
> 
> def css(n, r):
> if r == 0:
> return frozenset({frozenset()})
> elif len(n) == 0:
> return frozenset()
> else:
> rest = set(n)
> e = rest.pop()
> return frozenset([frozenset([e])
>   | l for l in list(css(rest, r-1))]) | css(rest, r)
> 
> >>> css(frozenset({1,2,3,4}), 2)
> frozenset({frozenset({2, 4}), frozenset({3, 4}), frozenset({2, 3}),
> frozenset({1, 3}), frozenset({1, 2}), frozenset({1, 4})})
> 
> The switch from lists (using +) and frozen sets using | is the most
> obvious change, but if the top-level argument might itself be a
> frozenset then the copy must be changed to a set constructor so that pop
> will work.

Yes…
Pop et al wont work with frozen sets
Containment wont work with sets — what mathematicians call 'not closed'
All of which amounts to this that python sets are not really pleasant for
math-work

[Just for context: A teacher may have more important things to teach than python
If the niggles get overbearing the vehicle may not be worth it
]

Besides I find the name pop ridiculous
Stacks imply a stronger order usage-discipline than lists
Sets are unordered compared to lists
To use a name traditionally reserved for a stack op on sets is quite nonsensical
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Gregory Ewing

Steve D'Aprano wrote:

[quoting Scott Stanchfield]
Figure 7: (Java) Defining a Dog pointer
Dog d;

When you write that definition, you are defining a pointer to a Dog
object, not a Dog object itself.
[end quote]

Here Scott mixes up what the compiler does (creates a pointer to a Dog object,
and what the programmer's Java code does (creates a Dog).


Um, no. The declaration 'Dog d' on its own does NOT create a Dog,
in any way, shape or form. It only declares something that can
*refer* to a Dog created elsewhere, which is what Scott is
quite correctly saying.


I expect this is because, as a "compiler guy", Scott probably doesn't really
believe that objects are values.


Please stop insulting Scott's intelligence, and that of other
"compiler guys", by suggesting that they don't understand things
as well as you do.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Installation issue with Python 3.6.2.

2017-09-05 Thread V Vishwanathan
 For the past 8/10 hours I have been trying to install the above version 
without any success.

My O/S is windows 10 free upgrade from win 8.1

Every time I try to install, I simply get a message as per screen grab attached.

I did have a version of 3.61 installed prior to upgrade to win 10, but somehow

it got corrupted ,and I simply uninstalled, and just not able to install again.

When I try the "Modify" option in the screen grab it proceeds and simply hangs

at " pre version"??

I will appreciate any help.

Than you,

Venkat



Sent from Mail for Windows 10


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Chris Angelico
On Tue, Sep 5, 2017 at 11:49 PM, Rustom Mody  wrote:
> Pop et al wont work with frozen sets
> Containment wont work with sets — what mathematicians call 'not closed'
> All of which amounts to this that python sets are not really pleasant for
> math-work

Funnily enough, Python has never boasted that it's great for
mathematicians. Time and time again I see posts here that try to
explain Python from the POV of pure mathematics, and they always seem
to end up getting convoluted and awkward. The real world is not so
pure... and Python lives happily in the real world.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to get values for skos/note, skos/notation and label in N-Triples

2017-09-05 Thread Chris Angelico
On Tue, Sep 5, 2017 at 11:40 PM, Dennis Lee Bieber
 wrote:
>
> {Post #6 in 6 days}
>
> On Tue, 5 Sep 2017 09:31:47 + (UTC), David Shi via Python-list
>  declaimed the following:
>
>> "Baginton E04009817"@en 
>>. 
>> "Live" 
>>. 
>> "E04009817" .
>>
>
 "How to get values for skos/note, skos/notation and label in N-Triples"
>
> The same way as for the other field as shown in the interactive 
> session
> I posted 20 hours ago -- did you read it? It took less than an hour of
> experimenting in the interpreter's interactive shell to answer your earlier
> post.

I think Google must be down for him.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Chris Angelico
On Tue, Sep 5, 2017 at 11:11 PM, Gregory Ewing
 wrote:
> Steve D'Aprano wrote:
>>
>> The third entity is the reference linking the name to the object (the
>> arrow).
>> This isn't a runtime value in Python, nor is it a compile time entity that
>> exists in source code. It is pure implementation, and as such, exists
>> outside
>> of the Python domain.
>
>
> The fact that there is a connection between the name and the
> object is very much part of Python's abstract semantics.
>
> There are different ways to implement that connection, but
> *any* implementation of Python has to include *some*
> representation of it.

Sure. But let's suppose you're building a Python implementation on top
of a language that has a perfectly good implementation of dict already
built for you. Literally every other namespace can be represented with
a dictionary, and the name:value association is that reference. Is the
reference *itself* a runtime value? No; you can't pick it up and move
it around - all you'll do is dereference it and get the value itself.
(Or you'll work with the name, as a string. That can sometimes serve
as a pseudo-reference.) Is it a compile time entity? Not directly
(assignment statements imply them, but they aren't themselves the
references). So Steve's comment is still correct.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Rustom Mody
On Tuesday, September 5, 2017 at 7:12:48 PM UTC+5:30, Rustom Mody wrote:
> On Tuesday, September 5, 2017 at 6:42:07 PM UTC+5:30, Gregory Ewing wrote:
> > Steve D'Aprano wrote:
> > > The third entity is the reference linking the name to the object (the 
> > > arrow).
> > > This isn't a runtime value in Python, nor is it a compile time entity that
> > > exists in source code. It is pure implementation, and as such, exists 
> > > outside
> > > of the Python domain.
> > 
> > The fact that there is a connection between the name and the
> > object is very much part of Python's abstract semantics.
> > 
> > There are different ways to implement that connection, but
> > *any* implementation of Python has to include *some*
> > representation of it.
> > 
> > There are also different words that can be used to describe
> > it. You can say that names are bound to objects, or that
> > names refer to objects, or that names hold references to
> > objects. These are all equally good ways of talking about
> > the exact same abstract concept.
> > 
> > To me this argument about whether Python has references
> > or not is like an American person saying that cars have
> > hoods, and a British person saying he's wrong, hoods
> > are an implementation detail and cars actually have
> > bonnets instead.
> 
> Also called playing humpty-dumpty
> 
> I believe there is a germ of value behind all this empty polemics 
> There are 3 equivalence relations:
> 1. == — mathematical, too coarse to understand nuances of python semantics
> 2. is — machine representation, too fine to be useful
> 3. graph (or topological) equality which experienced pythonistas have 
> internalized 
> in understanding when two data structures are same or different
> [Roughly Anton's diagrams that are beyond my drawing capability!]
> 
> 
> And yet pythonistas need that to understand python data structures
> 
> >>> a = [1,2]
> >>> b = [a,a]
> >>> c = [[1,2],[1,2]]
> >>> b == c
> True
> >>> b is c
> False
> >>> p = [1,2]
> >>> q = [p,p]
> >>> r = [[1,2],[1,2]]
> >>> q == r
> True
> >>> q is r
> False
> >>> b == q
> True
> >>> b == r
> True
> >>> b is q
> False
> >>> b is r
> False

To make it more clear
Suppose ≡ is graph-equal. The pythonista understands that
b ≢ c ## ≡ is finer than ==
Whereas
b ≡ r
ie ≡ is coarser than is

Its another matter that the name 'is' makes these discussions much harder in 
python
than in equivalent languages like java, lisp, javascript etc
by making the mostly unnecessary and irrelevant 
"is machine-rep same" sound the same(!) as "is conceptually same"
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Installation issue with Python 3.6.2.

2017-09-05 Thread Thomas Jollans
On 2017-09-05 15:24, V Vishwanathan wrote:
>  For the past 8/10 hours I have been trying to install the above version 
> without any success.
> 
> My O/S is windows 10 free upgrade from win 8.1
> 
> Every time I try to install, I simply get a message as per screen grab 
> attached.

This list is text only. There is no attachment.

> 
> I did have a version of 3.61 installed prior to upgrade to win 10, but somehow
> 
> it got corrupted ,and I simply uninstalled, and just not able to install 
> again.
> 
> When I try the "Modify" option in the screen grab it proceeds and simply hangs
> 
> at " pre version"??
> 
> I will appreciate any help.
> 
> Than you,
> 
> Venkat
> 
> 
> 
> Sent from Mail for Windows 10
> 
> 


-- 
Thomas Jollans
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Rustom Mody
On Tuesday, September 5, 2017 at 7:32:52 PM UTC+5:30, Chris Angelico wrote:
> On Tue, Sep 5, 2017 at 11:49 PM, Rustom Mody wrote:
> > Pop et al wont work with frozen sets
> > Containment wont work with sets — what mathematicians call 'not closed'
> > All of which amounts to this that python sets are not really pleasant for
> > math-work
> 
> Funnily enough, Python has never boasted that it's great for
> mathematicians. 

True that

> Time and time again I see posts here that try to
> explain Python from the POV of pure mathematics, and they always seem
> to end up getting convoluted and awkward.

Unrelated that.
Look at all the fundamental operations here
https://docs.python.org/3.6/library/operator.html

What percentage of these are unrelated to math?

And how do you write even the simplest assignment statement without a
(mathematical) expression on the rhs?

And a look at history:
What *were* Turing, Church, von Neumann, even Knuth by training? Mathematicians 
or CS-ists?

And what *are* the contributions of Turing, Church, von Neumann, Knuth to CS?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Chris Angelico
On Wed, Sep 6, 2017 at 12:19 AM, Rustom Mody  wrote:
> On Tuesday, September 5, 2017 at 7:32:52 PM UTC+5:30, Chris Angelico wrote:
>> On Tue, Sep 5, 2017 at 11:49 PM, Rustom Mody wrote:
>> > Pop et al wont work with frozen sets
>> > Containment wont work with sets — what mathematicians call 'not closed'
>> > All of which amounts to this that python sets are not really pleasant for
>> > math-work
>>
>> Funnily enough, Python has never boasted that it's great for
>> mathematicians.
>
> True that
>
>> Time and time again I see posts here that try to
>> explain Python from the POV of pure mathematics, and they always seem
>> to end up getting convoluted and awkward.
>
> Unrelated that.
> Look at all the fundamental operations here
> https://docs.python.org/3.6/library/operator.html
>
> What percentage of these are unrelated to math?
>
> And how do you write even the simplest assignment statement without a
> (mathematical) expression on the rhs?
>
> And a look at history:
> What *were* Turing, Church, von Neumann, even Knuth by training? 
> Mathematicians or CS-ists?
>
> And what *are* the contributions of Turing, Church, von Neumann, Knuth to CS?

Yes, mathematicians have contributed significantly to comp sci. And
people in suits have contributed to comp sci, too. Should we all wear
suits just because of the massive contributions from decades ago? Or
should we do what is best for solving our problems today?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Case-insensitive string equality

2017-09-05 Thread Grant Edwards
On 2017-09-03, Gregory Ewing  wrote:
> Stefan Ram wrote:
>>   But of
>>   course, actually the rules of orthography require "Maße" or
>>   "Masse" and do not allow "MASSE" or "MASZE", just as in
>>   English, "English" has to be written "English" and not
>>   "english" or "ENGLISH".
>
> While "english" is wrong in English, there's no rule
> against using  "ENGLISH" as an all-caps version.

Perhaps there's no "rule" in your book of rules, but it's almost
universally considered bad style and you will lose points with your
teacher, editor, etc.

On the inter-tubes generally indicates you're shouting, or just a
kook.  I guess if either of those is true, then it's good style.

-- 
Grant Edwards   grant.b.edwardsYow!
  at   
BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-BI-
  gmail.com

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Case-insensitive string equality

2017-09-05 Thread Chris Angelico
On Wed, Sep 6, 2017 at 12:27 AM, Grant Edwards
 wrote:
> On 2017-09-03, Gregory Ewing  wrote:
>> Stefan Ram wrote:
>>>   But of
>>>   course, actually the rules of orthography require "Maße" or
>>>   "Masse" and do not allow "MASSE" or "MASZE", just as in
>>>   English, "English" has to be written "English" and not
>>>   "english" or "ENGLISH".
>>
>> While "english" is wrong in English, there's no rule
>> against using  "ENGLISH" as an all-caps version.
>
> Perhaps there's no "rule" in your book of rules, but it's almost
> universally considered bad style and you will lose points with your
> teacher, editor, etc.
>
> On the inter-tubes generally indicates you're shouting, or just a
> kook.  I guess if either of those is true, then it's good style.

ENGLISH, Doc!

*Doc Brown proceeds to explain and/or demonstrate*

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Python console's workspace path

2017-09-05 Thread Andrej Viktorovich
Hello,

I run Python 3.6 console under windows 10. Where is default console directory?

I run script:
>>> tf = open ("aaa.txt", "w")
>>> tf.write(" %s" % 123)
>>> tf.close()

Where file aaa.txt will be created? Can I change default work space location? 
How?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python console's workspace path

2017-09-05 Thread Chris Angelico
On Wed, Sep 6, 2017 at 12:26 AM, Andrej Viktorovich
 wrote:
> Hello,
>
> I run Python 3.6 console under windows 10. Where is default console directory?
>
> I run script:
 tf = open ("aaa.txt", "w")
 tf.write(" %s" % 123)
 tf.close()
>
> Where file aaa.txt will be created? Can I change default work space location? 
> How?

Easy way to find out:

>>> import os
>>> os.getcwd()
'/home/rosuav'

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python console's workspace path

2017-09-05 Thread Rustom Mody
On Tuesday, September 5, 2017 at 7:58:23 PM UTC+5:30, Andrej Viktorovich wrote:
> Hello,
> 
> I run Python 3.6 console under windows 10. Where is default console directory?
> 
> I run script:
> >>> tf = open ("aaa.txt", "w")
> >>> tf.write(" %s" % 123)
> >>> tf.close()
> 
> Where file aaa.txt will be created? Can I change default work space location? 
> How?

>>> from os import getcwd
>>> getcwd()

You'll see where/what python takes as cwd (current working directory)

There are other things on windows like rt-click the python executable icon
on your desktop and adjust the "open in..." to whatever you want

But I dont know too much about this to say 😊
-- 
https://mail.python.org/mailman/listinfo/python-list


Run python module from console

2017-09-05 Thread Andrej Viktorovich
Hello,

I suppose I can run python module by passing module as param for executable:

python.exe myscr.py

But how to run script when I'm inside of console and have python prompt:

>>>


-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Run python module from console

2017-09-05 Thread Rustom Mody
On Tuesday, September 5, 2017 at 8:45:00 PM UTC+5:30, Andrej Viktorovich wrote:
> Hello,
> 
> I suppose I can run python module by passing module as param for executable:
> 
> python.exe myscr.py
> 
> But how to run script when I'm inside of console and have python prompt:
> 
> >>>

>> import myscr
# Note no .py extension
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python console's workspace path

2017-09-05 Thread MRAB

On 2017-09-05 15:31, Stefan Ram wrote:

Andrej Viktorovich  writes:

Hello,
I run Python 3.6 console under windows 10. Where is default console directory?
I run script:

tf = open ("aaa.txt", "w")
tf.write(" %s" % 123)
tf.close()


|>>> import os
|>>> os.getcwd()

Also, os.chdir(path) to change it, although it's better to work with 
absolute paths than change the working directory.

--
https://mail.python.org/mailman/listinfo/python-list


Re: Run python module from console

2017-09-05 Thread Ned Batchelder
On 9/5/17 11:16 AM, Stefan Ram wrote:
> Andrej Viktorovich  writes:
>> I suppose I can run python module by passing module as param for executable:
>> python.exe myscr.py
>> But how to run script when I'm inside of console and have python prompt:

The Python console isn't meant for ad-hoc execution of random scripts. 
It's designed for running one program, from the OS command line.  If you
need to run different scripts within one interpreter session, it might
be better to reorganize your code, or find a different execution
environment.

> exec( compile( open( 'myscr.py', 'rb' ).read(), 'myscr.py', 'exec' ))
>
>   . This looks quite complicated, but there are rumors
>   that Python 4 might have a »execfile« function, and
>   one then will be able to write:
>
> execfile(  'myscr.py' )

It's better to not start rumors about fictitious Python versions.

--Ned.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: tictactoe script - commented - may have pedagogical value

2017-09-05 Thread Ian Kelly
On Mon, Sep 4, 2017 at 9:26 PM,   wrote:
>
> """
> this program makes an optimal tictactoe move by answering the following 
> questions
> in their given order until it is told where to put its mark:
>
> 1) can you win the game?
> if so then do it
> 2) could your opponent win the game if it was his turn?
> if so then put your own mark where a mark of his would win him the game
> 3) could you win the game if you had two turns in a row?
> if so then make a move that leaves you with the largest number of second 
> moves
> that would win you the game if you could really make them
> 4) is the center square open?
> if so then put your mark there
> 5) are any of the corners open?
> if so then put your mark on one of them
> 6) put your mark on any open square
> """

I'm afraid its play is not optimal. Here's a transcript where the program lost.

Usually I've seen Tic Tac Toe implemented using the Minimax algorithm
since the decision tree for Tic Tac Toe is quite shallow.

py> play(oh)


 | |
-+-+-
 | |
-+-+-
 | |


cell number: 1


X| |
-+-+-
 |0|
-+-+-
 | |


cell number: 9


X| |0
-+-+-
 |0|
-+-+-
 | |X


cell number: 7


X| |0
-+-+-
 |0|
-+-+-
X|0|X


cell number: 4


X| |0
-+-+-
X|0|
-+-+-
X|0|X


X wins
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Run python module from console

2017-09-05 Thread Rustom Mody
On Tuesday, September 5, 2017 at 8:45:00 PM UTC+5:30, Andrej Viktorovich wrote:
> Hello,
> 
> I suppose I can run python module by passing module as param for executable:
> 
> python.exe myscr.py
> 
> But how to run script when I'm inside of console and have python prompt:
> 
> >>>

By and large not straightforwardly possible
At python prompt you call *functions*
At OS prompt you call apps/programs/scripts including python *scripts*
They are different with different calling conventions

However if you look up on the __name__ == '__main__' trick
you can find ways of getting both function call and script call behavior

https://stackoverflow.com/questions/419163/what-does-if-name-main-do
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Steve D'Aprano
On Tue, 5 Sep 2017 11:37 pm, Gregory Ewing wrote:

> Dennis Lee Bieber wrote:
>> Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference
>> semantics, in that the definition of a function declares how the
>> argument(s) are passed.
> 
> Well, sort of. In Pascal and Modula, and also VB I think,
> parameters are the only things that can be declared as having
> reference semantics, whereas references in C++ are first-class
> things that can be stored in any variable.

No, they aren't first-class. 

- It is not possible to refer to a reference after it is defined; any 
  occurrence of its name refers directly to the object it references.

- Since you cannot refer directly to a reference, but only the object
  it points to, you cannot have a reference to a reference.

- Containers of references are not allowed.

- Once a reference to an object is created, it cannot be changed to 
  reference another object ("to be reseated").

The last is only a limitation if you think of references as mutable pointers in
the C sense. But if you think of them as objects in the Python sense, that
makes them merely immutable.

But the inability to refer to the reference itself, the lack of references to
references, and the inability to have a container of references, makes them
second-class values -- or possibly not values at all.

(I don't know enough about C++ to distinguish between the last two opinions, but
I'm strongly leaning towards "not values at all".)



-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Run python module from console

2017-09-05 Thread Rhodri James

On 05/09/17 17:11, Stefan Ram wrote:

Ned Batchelder  writes:

exec( compile( open( 'myscr.py', 'rb' ).read(), 'myscr.py', 'exec' ))
. This looks quite complicated, but there are rumors
that Python 4 might have a »execfile« function, and
one then will be able to write:
execfile(  'myscr.py' )

It's better to not start rumors about fictitious Python versions.


   That was an attempt to make a kind of joke.

   The background is:

   Python 2 has »execfile«, but not Python 3.

   Another background is:

   We recently had this discussion, where Steve wrote:

|there should be a standard solution, instead of having to
|re-invent the wheel over and over again. Even when the wheel
|is only two or three lines.


The difference is that inventing this particular wheel is almost always 
a mistake.


--
Rhodri James *-* Kynesim Ltd
--
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Ned Batchelder
On 9/5/17 1:02 PM, Steve D'Aprano wrote:
> On Tue, 5 Sep 2017 11:37 pm, Gregory Ewing wrote:
>
>> Dennis Lee Bieber wrote:
>>> Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference
>>> semantics, in that the definition of a function declares how the
>>> argument(s) are passed.
>> Well, sort of. In Pascal and Modula, and also VB I think,
>> parameters are the only things that can be declared as having
>> reference semantics, whereas references in C++ are first-class
>> things that can be stored in any variable.
> No, they aren't first-class. 

Did you mis-read Gregory's claim? He said, "references *in C++* are
first-class things".  You seem to be talking below about Python things.

>
> - It is not possible to refer to a reference after it is defined; any 
>   occurrence of its name refers directly to the object it references.
>
> - Since you cannot refer directly to a reference, but only the object
>   it points to, you cannot have a reference to a reference.
>
> - Containers of references are not allowed.
>
> - Once a reference to an object is created, it cannot be changed to 
>   reference another object ("to be reseated").
>
> The last is only a limitation if you think of references as mutable pointers 
> in
> the C sense. But if you think of them as objects in the Python sense, that
> makes them merely immutable.
>
> But the inability to refer to the reference itself, the lack of references to
> references, and the inability to have a container of references, makes them
> second-class values -- or possibly not values at all.
>
> (I don't know enough about C++ to distinguish between the last two opinions, 
> but
> I'm strongly leaning towards "not values at all".)
>
>
>

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Steve D'Aprano
On Tue, 5 Sep 2017 11:08 pm, Stefan Ram wrote:

> Steve D'Aprano  writes:
>>[quote]
>>The mistake they make is in the definition of
>>Figure 7: (Java) Defining a Dog pointer
>>Dog d;
>>itself. When you write that definition, you are defining a pointer to a Dog
>>object, not a Dog object itself.
>>[end quote]
>>Here Scott mixes up what the compiler does (creates a pointer to a Dog object,
>>and what the programmer's Java code does (creates a Dog).
> 
>   I have not the whole context in mind, and so I might get
>   something wrong here, but if
> 
> Dog d;
> 
>   is supposed to be interpreted as Java, then it neither
>   creates a pointer to a Dog object nor it creates a Dog.
> 
>   Instead, it declares an unitialized variable d.


Thank you Stefan, your correction is noted. I'm not a Java expert like Scott,
and I failed to notice the distinction between:

Dog d;

and

Dog d = new Dog();

so I failed to realise that of course d has no value at all in Scott's example.




-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Chris Angelico
On Wed, Sep 6, 2017 at 3:15 AM, Ned Batchelder  wrote:
> On 9/5/17 1:02 PM, Steve D'Aprano wrote:
>> On Tue, 5 Sep 2017 11:37 pm, Gregory Ewing wrote:
>>
>>> Dennis Lee Bieber wrote:
 Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference
 semantics, in that the definition of a function declares how the
 argument(s) are passed.
>>> Well, sort of. In Pascal and Modula, and also VB I think,
>>> parameters are the only things that can be declared as having
>>> reference semantics, whereas references in C++ are first-class
>>> things that can be stored in any variable.
>> No, they aren't first-class.
>
> Did you mis-read Gregory's claim? He said, "references *in C++* are
> first-class things".  You seem to be talking below about Python things.
>

And everything Steve said was about C++ references, which are a form
of alias. Not a 'thing'.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Rustom Mody
On Tuesday, September 5, 2017 at 10:45:45 PM UTC+5:30, Ned Batchelder wrote:
> On 9/5/17 1:02 PM, Steve D'Aprano wrote:
> > On Tue, 5 Sep 2017 11:37 pm, Gregory Ewing wrote:
> >
> >> Dennis Lee Bieber wrote:
> >>> Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference
> >>> semantics, in that the definition of a function declares how the
> >>> argument(s) are passed.
> >> Well, sort of. In Pascal and Modula, and also VB I think,
> >> parameters are the only things that can be declared as having
> >> reference semantics, whereas references in C++ are first-class
> >> things that can be stored in any variable.
> > No, they aren't first-class. 
> 
> Did you mis-read Gregory's claim? He said, "references *in C++* are
> first-class things".  You seem to be talking below about Python things.

I think its mostly true of C++
And Steven did say:

(I don't know enough about C++ to distinguish between the last two opinions, but
I'm strongly leaning towards "not values at all".) 

So he seems to be talking of C++ (as analogous to python??)

But I dont see that any of it is relevant

Whether references are 
- first-class (Algol-68, pointers-in-C) or are simply
- second class (C++)
- invisible (python, lisp, ruby, javascript)

has little to do with what we are talking

The question is whether we need the *idea* of references
(modulo humpty-dumpty-fication)
to talk *about* the language; ie it needs to be there in the human/informal
ontology, even if the docs play word-games and try to avoid trigger-words
in honour of PC.

In my view its almost the defining quality of imperative languages that
the semantics of the language is not properly/fully comprehensive without
(something like) references.

[Replace "imperative language" with "assignment and mutation" if you like]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Run python module from console

2017-09-05 Thread Grant Edwards
On 2017-09-05, Andrej Viktorovich  wrote:
> Hello,
>
> I suppose I can run python module by passing module as param for executable:
>
> python.exe myscr.py
>
> But how to run script when I'm inside of console and have python prompt:
>


os.system("python.exe myscr.py")

-- 
Grant Edwards   grant.b.edwardsYow! I've read SEVEN
  at   MILLION books!!
  gmail.com

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Ned Batchelder


On 9/5/17 1:28 PM, Chris Angelico wrote:
> On Wed, Sep 6, 2017 at 3:15 AM, Ned Batchelder  wrote:
>> On 9/5/17 1:02 PM, Steve D'Aprano wrote:
>>> On Tue, 5 Sep 2017 11:37 pm, Gregory Ewing wrote:
>>>
 Dennis Lee Bieber wrote:
> Pascal, probably Modula-2, Visual BASIC are closer to the C++ reference
> semantics, in that the definition of a function declares how the
> argument(s) are passed.
 Well, sort of. In Pascal and Modula, and also VB I think,
 parameters are the only things that can be declared as having
 reference semantics, whereas references in C++ are first-class
 things that can be stored in any variable.
>>> No, they aren't first-class.
>> Did you mis-read Gregory's claim? He said, "references *in C++* are
>> first-class things".  You seem to be talking below about Python things.
>>
> And everything Steve said was about C++ references, which are a form
> of alias. Not a 'thing'.

I see, I misunderstood. Sorry for the distraction.

>
> ChrisA

-- 
https://mail.python.org/mailman/listinfo/python-list


seeking advice about strategic-game ai

2017-09-05 Thread namenobodywants
i plan to try writing an ai for a strategic game, and i've pretty much narrowed 
the candidates down to either checkers or 

reversi. i would prefer to tackle the easier game, so can anybody tell me which 
one is easier to program decently? (or maybe 

i'm missing a good candidate - basically all i want is a game that's less 
trivial than tictactoe). by "decently" i mean that it 

should make reasonably skillful moves in a reasonable amount of time, but speed 
and playing strength take a backseat to the 

simplicity and well-motivatedness of the algorithm. (this isn't supposed to be 
a professional-caliber ai ... it will be more like a 

kid's science-fair project). 

more particularly, can anybody give me some high-level guidance about 
evaluation functions for either game? (no spoilers 

please - i want this to be really my own project). as far as reversi goes, my 
ideas on this matter are based mostly on the 

"basic diagram" in goro hasegawa's "how to win at othello". (i have a library 
hold on norvig's "paradigms of ai programming", 

which devotes an entire chapter to reversi, but the book hasn't come in yet). 
as for checkers, i was thinking about a weighted 

sum of three basic measurements ... if "you" and "i" are the players, then i 
would measure

*) (my relative mobility)  = (the number of moves i have) - (the number 
of moves you have)
*) (my relative king presence)  = (the number of kings i have)  - (the number 
of kings you have)
*) (my relative pawn presence) = (the number of pawns i have) - (the number of 
pawns you have)

indeed, i've even wondered whether a viable evaluation could be based on 
relative mobility alone - that would, after all, work 

perfectly if there were no limit to the search horizon - but on the other hand 
i'm also prepared to find out that any viable 

evaluation needs to be more sophisticated. i wouldn't be surprised, for 
example, if the approach i'm suggesting could work 

but only if the weights in the sum are adjusted according to the number of 
moves made or some other criterion. 

anyway, that should suffice to give you an idea of where i'm at with this. 
thanks if you can help

peace
stm 
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python console's workspace path

2017-09-05 Thread eryk sun
On Tue, Sep 5, 2017 at 9:26 AM, Andrej Viktorovich
 wrote:
>
> I run Python 3.6 console under windows 10. Where is default console directory?

The working directory for the console (i.e. conhost.exe) is irrelevant
to Python. So I assume you mean the default working directory of the
Python shell (i.e. the REPL). There isn't one. It's set by or
inherited from the parent process.

> Can I change default work space location?

For interactive work, set the PYTHONSTARTUP environment variable to
the fully-qualified path of a startup script. Set the working
directory in this script via os.chdir("fully/qualified/path").

For a script, the working directory should not be used to find private
resources. Use the script/package directory for read-only resources
and otherwise use a platform-dependent data directory (e.g. on Windows
use a subdirectory of %LocalAppData% or %ProgramData%).
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I find what kind of exception is thrown.

2017-09-05 Thread Antoon Pardon
On 05-09-17 13:39, Steve D'Aprano wrote:
> On Tue, 5 Sep 2017 06:50 pm, Antoon Pardon wrote:
> 
>> Python 2.6.4 on a solaris box.
>>
>> I have a program in which all kind of excptions can be thrown and caugth.
>> The main program is something like below:
>>
>> try:
>> do_stuff
>> except Exception:
>> log unexpected trouble
>>
>> Now I found the following in the logs: [Errno 131] Connection reset by peer
>>
>> This is a problem I would like to catch earlier however I have no idea what
>> exception I would have to catch in order to treat this case.
> 
> 
> try:
> do_stuff
> except Exception as err:
> print err, type(err)

Thabks, I should have thought of that.

It turned out to be a socket.error, which wasn't obvious to find
since I didn't use the socket module directly.

-- 
Antoon Pardon.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python console's workspace path

2017-09-05 Thread Terry Reedy

On 9/5/2017 10:26 AM, Andrej Viktorovich wrote:

Hello,

I run Python 3.6 console under windows 10. Where is default console directory?


It depends on how and where you start it.


I run script:

tf = open ("aaa.txt", "w")
tf.write(" %s" % 123)
tf.close()


Where file aaa.txt will be created?


I have compiled 3.7 as F:\\dev\\3x\\PCbuild\\win32\\python_d.exe.  I 
suspect I originally started it from Explorer, so it started in
'F:\\dev\\3x\\PCbuild\\win32'.  I then pinned it to the task bar.  Left 
clicking the icon restarts it in the same directory.  If I right click 
the icon and then right click 'Python', I see Properties, which shows 
"Start in" and a box with the path above.  The Start in value can be edited.


If you start python with a console command, instead of an icon, the 
initial directory is instead the current directory when you issue the 
command.



Can I change default work space location? How?


By editing the icon (Rustom Mody), changing the directory before issuing 
a startup command, or with os.chdir (MRAB).


--
Terry Jan Reedy

--
https://mail.python.org/mailman/listinfo/python-list


Re: tictactoe script - commented - may have pedagogical value

2017-09-05 Thread namenobodywants
good point. this algorithm doesn't take account of the fact that one can make a 
threat (x's 147) by parrying a threat (o's 357). nevertheless i'm still certain 
that the components the algorithm is built from are the same components i use 
myself to play tictactoe, and i'm still certain that my own tictactoe playing 
is optimal. that's my motivation for doing it this way: i'm trying to formalize 
the algorithm i use myself. besides, exhaustive minimax search seems like 
cheating to me, since it doesn't generalize to less-trivial games. anyway, 
thanks for pointing out the error

peace
stm
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I find what kind of exception is thrown.

2017-09-05 Thread William Ray Wing

> On Sep 5, 2017, at 4:50 AM, Antoon Pardon  wrote:
> 
> Python 2.6.4 on a solaris box.
> 
> I have a program in which all kind of excptions can be thrown and caugth.
> The main program is something like below:
> 
> try:
>do_stuff
> except Exception:
>log unexpected trouble
> 
> Now I found the following in the logs: [Errno 131] Connection reset by peer
> 

“Connection reset by peer” is a network problem.  It looks to your program as 
though the connection has been dropped.

> This is a problem I would like to catch earlier however I have no idea what
> exception I would have to catch in order to treat this case.
> 
> -- 
> Antoon Pardon
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Steve D'Aprano
On Tue, 5 Sep 2017 11:47 pm, Gregory Ewing wrote:

> Steve D'Aprano wrote:
>> [quoting Scott Stanchfield]
>> Figure 7: (Java) Defining a Dog pointer
>> Dog d;
>> 
>> When you write that definition, you are defining a pointer to a Dog
>> object, not a Dog object itself.
>> [end quote]
>> 
>> Here Scott mixes up what the compiler does (creates a pointer to a Dog
>> object, and what the programmer's Java code does (creates a Dog).
> 
> Um, no. The declaration 'Dog d' on its own does NOT create a Dog,
> in any way, shape or form. It only declares something that can
> *refer* to a Dog created elsewhere, which is what Scott is
> quite correctly saying.

That's not what he said. I quoted him: he quite clearly states that d defines a
pointer to a Dog object. He doesn't say that you're declaring an empty slot
that is waiting to be filled with a pointer to a dog. He says it defines a
pointer.

So which Dog object does this pointer point to? Answer: there isn't one. There
may not even be any Dog object existing in the entire program up to this point.

Even allowing that there were a Dog to be pointed to, how do we inspect or
manipulate that pointer? Answer: you can't, because pointers are not meaningful
values in Java.

There's no(?) Java code you can write that allows this:

Dog d;
java.lang.System.out.println( address of variable d );
java.lang.System.out.println( address of the Dog d points to );

Maybe compiler-specific debugging tools? I don't know enough Java to
*categorically* rule it out, but if it exists at all, it would be unsafe to
rely on the addresses you get.

You're right that I made a mistake. I'm not a Java expert like Scott
Stanchfield, and I was led astray by his misleading explanation, and failed to
notice that d didn't have a value. (What's his excuse for not noticing?)

As Stefan already pointed out, the code Scott gives does not define a value, but
is just a declaration of a variable name. At that point, d has no value at all,
and you get a compile time error if you try to access d. There is no Dog, and
no pointer to a Dog. There's just a name (or variable if you prefer).

So what's the value of d? It doesn't have one. Scott's explanation is
misleading: `Dog d;` does not define *any value at all*, let alone a pointer.

I daresay that Scott could attempt to justify his wording. I imagine it might go
something like this:


Of course d is a pointer to a value. The Java compiler keeps a table
mapping variable names to memory addresses, and the name 'd' is mapped
to some address in the table. That address must hold some value, even
if it is uninitialised memory filled with arbitrary bytes. That address
is a (possibly null, possibly invalid) pointer to a Dog object.
-- Me, channelling what I think Scott *might* say.

Notice how this mixes *three* different abstractions? There's the top-level Java
abstraction, where we declare d as a Dog. There's the compiler abstraction,
where we talk about mapping variable names to memory addresses, and pointers to
Dog objects. And there's an even lower abstraction, where we talk about memory
filled with arbitrary bytes.

And so long as we keep track of which abstraction we're in, this is fine. It
doesn't even have to be explicit: once people gain enough experience, they can
effortlessly and implicitly swap between abstractions and not even notice.
That's sometimes a good thing, but its a bad thing when we lose track of the
abstraction level and confuse others (like me!), or even ourselves, and lead
to "Not Even Wrong" questions like this:

https://stackoverflow.com/questions/1961146/memory-address-of-variables-in-java

(Likewise for people thinking that id() in Python returns a memory address, and
ask how to dereference that address.)

Not all explanations are equally useful, even if they are correct for some
definition of "correct".


In Python, the equivalent to Scott's code `Dog d;` would be something like this:

# --- %< ---

class Dog:
pass

global x
assert isinstance(x, Dog)

# --- %< ---

except that we get a runtime NameError instead of a compile-time error. Would
you like to say that this code "defines a pointer to a Dog"? I should hope not.
How is it different from Scott's example of `Dog d;`?



>> I expect this is because, as a "compiler guy", Scott probably doesn't really
>> believe that objects are values.
> 
> Please stop insulting Scott's intelligence, and that of other
> "compiler guys", by suggesting that they don't understand things
> as well as you do.

Why shouldn't I suggest that Scott got something wrong? What makes him, and
other "compiler guys", so special that they are infallible and can't make
mistakes? Argument by authority is at best the weakest form of argument, if it
isn't an outright fallacy.

https://en.wikipedia.org/wiki/Argument_from_authority

I'm not questioning his intelligence. I'm questioning his *perspective*, and his
failure to distinguish between different lev

Re: A question on modification of a list via a function invocation

2017-09-05 Thread Chris Angelico
On Wed, Sep 6, 2017 at 5:28 AM, Dennis Lee Bieber  wrote:
> On 5 Sep 2017 17:57:18 GMT, r...@zedat.fu-berlin.de (Stefan Ram) declaimed
> the following:
>
>>  But what does "a C++ reference" refer to?
>>
>
> Per Stroustrup (The C++ Programming Language 4th Ed, page 189)
>
> """
> * ...
> * A reference always refers to the object to which it was initialized.
> * ...
>
> A reference is an alternative name for an object, an alias. ...
> """
>
> {Hmmm, and I see that the syntax can be used outside of parameter
> declaration -- which is the only place I'd seen it previously... either
> this is a change from earlier standards, or my classes just didn't feel the
> need to expose a non-parameter reference -- since, based upon the above
> book, you can not declare a bare reference "variable"; it MUST be
> initialized with a real object.}

Outside of parameters, there's very little practical reason for
aliases. Their primary value is that an internal name can be an alias
for an external object, which is achieved with reference parameters.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread MRAB

On 2017-09-05 20:08, Steve D'Aprano wrote:

On Tue, 5 Sep 2017 11:47 pm, Gregory Ewing wrote:


Steve D'Aprano wrote:

[quoting Scott Stanchfield]
Figure 7: (Java) Defining a Dog pointer
Dog d;

When you write that definition, you are defining a pointer to a Dog
object, not a Dog object itself.
[end quote]

Here Scott mixes up what the compiler does (creates a pointer to a Dog
object, and what the programmer's Java code does (creates a Dog).


Um, no. The declaration 'Dog d' on its own does NOT create a Dog,
in any way, shape or form. It only declares something that can
*refer* to a Dog created elsewhere, which is what Scott is
quite correctly saying.


That's not what he said. I quoted him: he quite clearly states that d defines a
pointer to a Dog object. He doesn't say that you're declaring an empty slot
that is waiting to be filled with a pointer to a dog. He says it defines a
pointer.

So which Dog object does this pointer point to? Answer: there isn't one. There
may not even be any Dog object existing in the entire program up to this point.

Even allowing that there were a Dog to be pointed to, how do we inspect or
manipulate that pointer? Answer: you can't, because pointers are not meaningful
values in Java.

There's no(?) Java code you can write that allows this:

 Dog d;
 java.lang.System.out.println( address of variable d );
 java.lang.System.out.println( address of the Dog d points to );

Maybe compiler-specific debugging tools? I don't know enough Java to
*categorically* rule it out, but if it exists at all, it would be unsafe to
rely on the addresses you get.


d is initialised to null. You can check for null:

if (d == null)
java.lang.System.out.println("There's no dog.");
else
d.bark();
--
https://mail.python.org/mailman/listinfo/python-list


Re: Hatch - A modern project, package, and virtual env manager

2017-09-05 Thread ofekmeister
0.4.0 is out now!
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Chris Angelico
On Wed, Sep 6, 2017 at 5:48 AM, Stefan Ram  wrote:
>   Depends on the meaning of "meaningful". In Java, one can
>   inspect and manipulate pointers like in this program for
>   example:
> [chomp code]

That shows that the Java '==' operator is like the Python 'is'
operator, and checks for object identity. You haven't manipulated
pointers at all. In contrast, here's a C program that actually
MANIPULATES pointers:

#include 
void do_stuff(int *x)
{
printf("x (%p) points to %d\n", x, *x);
x += 2;
printf("Now x (%p) points to %d\n", x, *x);
}
int main()
{
int x[3] = {28, 42, 79};
do_stuff(x); /* or do_stuff(&x[0]); */
return 0;
}

You can't do this with Python, since pointer arithmetic fundamentally
doesn't exist. You can in C. Can you in Java?

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Chris Angelico
On Wed, Sep 6, 2017 at 6:42 AM, Stefan Ram  wrote:
> Chris Angelico  writes:
>>here's a C program that actually MANIPULATES pointers:
> ...
>>x += 2;
> ...
>>You can in C. Can you in Java?
>
>   »dog = null« in Java would correspond to »x = 0« in C.
>
>   It seems, to you, an assignment of »x + 2« to »x« is
>   "manipulation", while an assignment of »0« to »x« is not.
>
>   Well, if you define the term "manipulation" to get the
>   results you intend, no one can prove you wrong, but your
>   words might be harder to understand when they do not use
>   the English meanings of words (like "manipulate") but your
>   ad-hoc meanings.
>

dog = null in Java corresponds to x = None in Python. It's a null
reference, but that's still a specific "thing". A fully compliant
Python implementation could use a NULL pointer to represent the None
object, as long as it correspondingly interprets such a pointer as
representing None.

In all of your Java examples, you're causing a name to refer to either
an object or null, and everything you do can be explained in terms of
name bindings Python-style.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


bussiness python

2017-09-05 Thread jessicayates59
Here's a code that I have, i'm getting an error in line 5 and i'm not sure why, 


# future value of annuity
p = 1000
r = 2/100
n = 5
FV= p * ((1+r) ** n - 1/r)
print(FV)

#FV of annuity- continuous compounding
CF= 1000
r = 6/100/12
t = 12
import math
FV= CF * ((1 + (r/n)) ** (n*t))
print (FV)


#Annuity (FV)- solve for n
import math
FV= 19600
r = 5/100
p = 1000
n = math.log(1 + FV*r / p) / math.log(1+r)
print(n)


# annuity payments
PV= 10 # how much
r = 5/100 # interest rate
n = 10 #how many years
p = r * (PV) / ((1 + r) ** n - 1)

print(p)

a = [1,2,3] # a list is just like an array, a list is mutable ( the objects can 
change)
b = a # b is pointing at the same list as a
print (type (a), id(a))
print (type(b), id(b))

the output is supposed to be
 5204.040160005
12336.416801016496
14.000708059400562
12350.45749654566




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Marko Rauhamaa
Chris Angelico :

> That shows that the Java '==' operator is like the Python 'is'
> operator, and checks for object identity. You haven't manipulated
> pointers at all. In contrast, here's a C program that actually
> MANIPULATES pointers:
>
> [...]
>
> You can't do this with Python, since pointer arithmetic fundamentally
> doesn't exist. You can in C. Can you in Java?

You can't do it in Pascal, either, but Pascal definitely has pointers.

Pointer arithmetics is not an essential part of C. One could argue that
it was a mistake to include it in the language.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Grant Edwards
On 2017-09-05, Marko Rauhamaa  wrote:

> Pointer arithmetics is not an essential part of C. One could argue that
> it was a mistake to include it in the language.

One may argue that it was a mistake, but I remember at least one
implementation where pointer arithmetic was hugely more efficient than
indexing into arrays.  Incrementing a pointer through an array was
way, way faster than indexing through the array by incrementing an
array subscript.

But, that was 25 years ago on an 8-bit CPU where where integer
multiplies were expensive.  The last time I compare the two methods
with a recent GCC on a 32-bit CPU, it generated pretty much the same
code either way...

-- 
Grant Edwards   grant.b.edwardsYow! Someone in DAYTON,
  at   Ohio is selling USED
  gmail.comCARPETS to a SERBO-CROATIAN

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I find what kind of exception is thrown.

2017-09-05 Thread Ben Finney
Antoon Pardon  writes:

> Python 2.6.4 on a solaris box.
>
> I have a program in which all kind of excptions can be thrown and caugth.
> The main program is something like below:
>
> try:
> do_stuff
> except Exception:
> log unexpected trouble

You're throwing away the exception object, with the information you
need.

Instead::

try:
do_stuff()
except Exception as exc:
log_unexpected_trouble(exc)

> Now I found the following in the logs: [Errno 131] Connection reset by peer

That doesn't have the exception type in it. Probably because you are
logging only ‘str(exc)’, which returns the exception message.

If you *also* want the exception type to be logged, you'll need to get
at it.

You could use ‘"{0.__class__.__name__}: {0}".format(exc)’.

> This is a problem I would like to catch earlier however I have no idea
> what exception I would have to catch in order to treat this case.

Start by logging what exceptions actually occur, complete with their
types. Then, when you have more data, decide which ones you need to
handle specially and which ones can propagate normally.

-- 
 \   “An idea isn't responsible for the people who believe in it.” |
  `\  —Donald Robert Perry Marquis |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: bussiness python

2017-09-05 Thread MRAB

On 2017-09-05 22:21, jessicayate...@gmail.com wrote:

Here's a code that I have, i'm getting an error in line 5 and i'm not sure why,


# future value of annuity
p = 1000
r = 2/100
n = 5
FV= p * ((1+r) ** n - 1/r)
print(FV)


[snip]


the output is supposed to be
  5204.040160005

[snip]

Your formula is wrong. The second closing parenthesis is in the wrong place.

That line should be:

FV = p * ((1 + r) ** n - 1) / r
--
https://mail.python.org/mailman/listinfo/python-list


Re: bussiness python

2017-09-05 Thread timetowalk
On Tuesday, September 5, 2017 at 8:28:00 PM UTC-4, MRAB wrote:
> On 2017-09-05 22:21, jessicayate...@gmail.com wrote:
> > Here's a code that I have, i'm getting an error in line 5 and i'm not sure 
> > why,
> > 
> > 
> > # future value of annuity
> > p = 1000
> > r = 2/100
> > n = 5
> > FV= p * ((1+r) ** n - 1/r)
> > print(FV)
> > 
> [snip]
> 
> > the output is supposed to be
> >   5204.040160005
> [snip]
> 
> Your formula is wrong. The second closing parenthesis is in the wrong place.
> 
> That line should be:
> 
> FV = p * ((1 + r) ** n - 1) / r



For line #3, r = 2/100 is zero.
For line #5, 1/r will cause an exception
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Steve D'Aprano
On Wed, 6 Sep 2017 12:19 am, Rustom Mody wrote:

> And how do you write even the simplest assignment statement without a
> (mathematical) expression on the rhs?

name = other_name

is not a mathematical expression. Its giving something a new name.

name = obj.attribute

is not a mathematical expression. (That's not a dot product.)



> What were Turing, Church, von Neumann, even Knuth by training? Mathematicians
> or CS-ists? 
> 
> And what are the contributions of Turing, Church, von Neumann, Knuth to CS?

Who cares? We're talking about Python, not Computer Science.





-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: bussiness python

2017-09-05 Thread MRAB

On 2017-09-06 01:40, timetowalk wrote:

On Tuesday, September 5, 2017 at 8:28:00 PM UTC-4, MRAB wrote:

On 2017-09-05 22:21, jessicayate...@gmail.com wrote:
> Here's a code that I have, i'm getting an error in line 5 and i'm not sure 
why,
> 
> 
> # future value of annuity

> p = 1000
> r = 2/100
> n = 5
> FV= p * ((1+r) ** n - 1/r)
> print(FV)
> 
[snip]


> the output is supposed to be
>   5204.040160005
[snip]

Your formula is wrong. The second closing parenthesis is in the wrong place.

That line should be:

FV = p * ((1 + r) ** n - 1) / r




For line #3, r = 2/100 is zero.
For line #5, 1/r will cause an exception


The error wasn't specified.

The print lines have parentheses, which is suggestive of Python 3. If it 
was Python 2, those lines probably wouldn't have the parentheses.

--
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Rustom Mody
On Wednesday, September 6, 2017 at 3:34:41 AM UTC+5:30, Marko Rauhamaa wrote:
> Chris Angelico :
> 
> > That shows that the Java '==' operator is like the Python 'is'
> > operator, and checks for object identity. You haven't manipulated
> > pointers at all. In contrast, here's a C program that actually
> > MANIPULATES pointers:
> >
> > [...]
> >
> > You can't do this with Python, since pointer arithmetic fundamentally
> > doesn't exist. You can in C. Can you in Java?
> 
> You can't do it in Pascal, either, but Pascal definitely has pointers.
> 
> Pointer arithmetics is not an essential part of C. One could argue that
> it was a mistake to include it in the language.

This is subjective of course… but still I wonder where you are coming from…

You of course know that writing Unix was the genesis and raison d'être for C 
right?

And what is an OS but a thin layer of abstraction on top of bare ISP?
ie is not a Linux-OS just an x86 hw + some new ‘instructions’ called
system-calls?

Which is to say IMHO being able to punch holes into the hi-level-language 
abstraction seems to be a sine qua non for being suitable as a language for 
writing OSes.
Do you think its reasonable/feasible to do that without easy access to all the 
machine resources eg memory, IO, interrupts etc accessible in the OS-writing 
language?

[BTW I think Microsoft has done a better job than classic C of repeating this 
with C# — C# is almost as high-level as python, lisp etc and as low (or lower)
than C; ie it is effectively two languages, called ‘safe’ and ‘unsafe’ parts
]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Case-insensitive string equality

2017-09-05 Thread Steve D'Aprano
On Wed, 6 Sep 2017 12:27 am, Grant Edwards wrote:

> On 2017-09-03, Gregory Ewing  wrote:
>> Stefan Ram wrote:
>>>   But of
>>>   course, actually the rules of orthography require "Maße" or
>>>   "Masse" and do not allow "MASSE" or "MASZE", just as in
>>>   English, "English" has to be written "English" and not
>>>   "english" or "ENGLISH".
>>
>> While "english" is wrong in English, there's no rule
>> against using  "ENGLISH" as an all-caps version.
> 
> Perhaps there's no "rule" in your book of rules, but it's almost
> universally considered bad style and you will lose points with your
> teacher, editor, etc.

And yet editors frequently use ALL CAPS for book titles and sometimes even
chapter headings, as well as the author's name. I have a shelf full of books by
STEPHEN KING behind me.

Likewise for movie titles on DVDs, album titles on CDs, address labels (I'm
looking at a letter addressed to MR S DAPRANO right now), labels on food and
medication.

The late and much-lamented English humourist Sir Terry Pratchett wrote almost
forty books including the character of Death, who SPEAKS IN CAPITALS. (And his
superior, Azrael, does the same in letters almost the size of the entire page.
Fortunately he says only a single word in the entire series.)

Many government forms and databases require all caps, presumably because it is
easier for handwriting recognition, or maybe its just a left over from the days
of type writers.


> On the inter-tubes generally indicates you're shouting, or just a
> kook.  I guess if either of those is true, then it's good style.

It is true that in general we don't write ordinary prose in all caps, there are
plenty of non-kook uses for it. But speaking of capitals on the Internet:



 HI EVERYBODY!!
 try pressing the the Caps Lock key
 O THANKS!!! ITS SO MUCH EASIER TO WRITE NOW!!!
 fuck me


http://bash.org/?835030


-- 
Steve
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Rustom Mody
On Wednesday, September 6, 2017 at 6:27:24 AM UTC+5:30, Steve D'Aprano wrote:
> On Wed, 6 Sep 2017 12:19 am, Rustom Mody wrote:
> 
> > And how do you write even the simplest assignment statement without a
> > (mathematical) expression on the rhs?
> 
> name = other_name
> 
> is not a mathematical expression. Its giving something a new name.
> 
> name = obj.attribute
> 
> is not a mathematical expression. (That's not a dot product.)
> 

Ok you win (that)
[And I see your stocks of straw are overflowing. Wholesale prices?]

> 
> 
> > What were Turing, Church, von Neumann, even Knuth by training? 
> > Mathematicians
> > or CS-ists? 
> > 
> > And what are the contributions of Turing, Church, von Neumann, Knuth to CS?
> 
> Who cares? We're talking about Python, not Computer Science.

He who forgets history is doomed to repeat it.
Start with your own statement: “Lisp is a functional language”
And see the history a little bit more
http://blog.languager.org/2015/04/cs-history-1.html

1960 : McCarthy got the idea of functional programming from an earlier invention
of a certain Backus called 'The Formula Translator' which would later
shorten to ForTran

1980s: The functional programming community was decrying lisp:
"Success of lisp set back the development of functional programming by 10 years"

And most significant: “McCarthy did not consider Lisp to be a functional 
language”

Of course nothing to be surprised here: You know more java than old java-heads
And more lisp than John McCarthy 😉
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Ben Finney
r...@zedat.fu-berlin.de (Stefan Ram) writes:

>   In mathematics, every author is free to give his own
>   definitions to concepts and create his own notation.

In one trivial sense that is true. Anyone can define any term to mean
whatever they like. This is a perfectly sherbert thing to do.

In a more useful sense: No, that is not true. The freedom to redefine
terms to mean whatever one likes, is constrained by the inherent barrier
that poses to clear communication.

Authors are not free to give personal definition to concepts, because
the transmission of those definitions is not free. The other parties in
the communication are not empty vessels waiting for the thoughts of the
author.

Or, in other words: For established terms in the field, an author has
freedom to redefine those terms only to the extent that the author
discards clear communication with those who already use the established
meanings.

> >Who cares? We're talking about Python, not Computer Science.
>
>   Yes. To this I agree! I try not to be the first poster who mentions
>   C++, Java, or mathematics in a thread. But sometimes I can't resist
>   to answer when someone else mentions these topics.

The ‘=’ symbol in Python is well established, with a meaning that is
*not* a declaration of equality. Using the ‘=’ in a forum to discuss the
Python language, is not a mention of – nor an invitation to invoke –
mathematics, nor C++, nor Java.

-- 
 \ “If nothing changes, everything will remain the same.” —Barne's |
  `\   Law |
_o__)  |
Ben Finney

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Rustom Mody
On Wednesday, September 6, 2017 at 6:58:29 AM UTC+5:30, Rustom Mody wrote:
> On Wednesday, September 6, 2017 at 6:27:24 AM UTC+5:30, Steve D'Aprano wrote:
> > On Wed, 6 Sep 2017 12:19 am, Rustom Mody wrote:
> > > What were Turing, Church, von Neumann, even Knuth by training? 
> > > Mathematicians
> > > or CS-ists? 
> > > 
> > > And what are the contributions of Turing, Church, von Neumann, Knuth to 
> > > CS?
> > 
> > Who cares? We're talking about Python, not Computer Science.
> Of course nothing to be surprised here: You know more java than old java-heads
> And more lisp than John McCarthy 😉

Also noteworthy here: You know more about list comprehensions than their 
inventor — Greg Ewing
[No I normally would not call Greg their inventor but in this case following
through your logic that python exists in a historical, contextual vacuum]
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How do I find what kind of exception is thrown.

2017-09-05 Thread Paul Rubin
Antoon Pardon  writes:
> Now I found the following in the logs: [Errno 131] Connection reset by peer
> This is a problem I would like to catch earlier

I'd expect that's an IOError thrown by the socket library.  You could
just let it go uncaught and see what you get in the crash dump.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Run Windows commands from Python console

2017-09-05 Thread Rick Johnson
Terry Reedy wrote:
> Rick Johnson wrote:

[...] 

> > When i'm away from an editor (like IDLE, for instance),
> > one of the features i miss most is the ability to right
> > click the line of the exception message (you know, the one
> > that includes the offending line number and offending
> > script filepath), and choose "open script for editing"
> > from a contextual menu, which will open the script and
> > automatically scroll down to the offending line for me.
> > Ahhh, efficient bliss.
> 
> 'Goto file/line' also works on the grep/find-in-files
> Output Window. I must have used this about 30 times in 8
> outputs tonight try to track down bugs in a proposed IDLE
> patch. There were no tracebacks, just thinkgs not working.

Yes, the find-in-files feature gets a lot of usage from me
as well, when i'm "IDLE'ing" ;-)

> I plan to make it a bit faster by moving the option to the
> top of the menu.

Speaking of "end-user interface customizations"... one
feature that i have yet to find, in any modern GUI, is the
ability to move menu commands around at mere whim. I find
that many times, devs don't put enough thought into these
things.

Another menuing feature that might be helpful, is a "recent
commands" listing, that will list a handful of the most
recently used commands, and keep them handy for quick
access.

One of the nice (current) features of Tkinter menus (that i
sometimes miss on my windows box!) is the ability to "tear-
off" a menu cascade and use it as a sort of "pseudo tool
bar". Of course, the tear-off feature may be limited, as you
are confined to dealing with textual commands, as opposed to
space-saving icons, but for those who have an aversion to
Rachmaninoff-style key chording, a helpful feature
nonetheless!

> I have thought about making it even faster by not having to
> use the context menu -- just click, or maybe double click,
> and the jump happens.  What do you think?

I think that would be a great idea for the find-in-files
output window, since after all, it is a single purpose tool.
I myself have a stand-alone grep tool with a "double click
to edit" event bound, and i do find the click (one step) to
be far more efficient than a contextual menu (two steps).
Since, when you open a contextual menu, there is that
moment of distraction while you search for the correct
command.

However, i'm not sure if dynamic mouse events in IDLE's
pyshell (aka: "REPL window") are a good idea, as an
accidental click in an exception dump would cause surprise
windows to pop up, and could be confusing to noobs. What is
your opinion on this?

Additionally, in the find-in-files window, it might be
helpful to also add a short message (using a tk.Label
perhaps?) above the "output area" (which i assume is a
tk.Text?), informing the user to "Double-click a path to
edit with IDLE" -- or something informative like that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Steve D'Aprano
On Tue, 5 Sep 2017 11:11 pm, Gregory Ewing wrote:

> Steve D'Aprano wrote:
>> The third entity is the reference linking the name to the object (the arrow).
>> This isn't a runtime value in Python, nor is it a compile time entity that
>> exists in source code. It is pure implementation, and as such, exists outside
>> of the Python domain.
> 
> The fact that there is a connection between the name and the
> object is very much part of Python's abstract semantics.
> 
> There are different ways to implement that connection, but
> *any* implementation of Python has to include *some*
> representation of it.

Any *what* of Python? Oh, that's right, you said any *implementation* of Python.

Isn't that what I said? That references are a property of the implementation,
not of the language. You are inadvertently agreeing with me.

- You can't bind a reference to a name in Python. Names are always bound to
objects. 

- You can't have a list or set of references, only lists or sets of objects.

- You can't form a reference to a reference.

- You can't use references to implement pass-by-reference semantics.

- You can't view or inspect references in Python (maybe in ctypes, 
  or in a debugger, but those aren't part of the Python language, 
  they are implementation-specific interfaces to the interpreter).


So in what sense are references part of the Python language?

My answer is that they are not. They're a part of the implementation, which
makes them different from values (ints, floats, strings, lists, and other
objects, whether built-in or not). It makes them different from other
conceptual entities in Python like for-loops, comprehensions, try...except
blocks etc, which aren't values but they are properties of the program (at
least of the source code, if not the byte code).


> There are also different words that can be used to describe
> it. You can say that names are bound to objects, or that
> names refer to objects, or that names hold references to
> objects.

As they used to say in Sesame Street, "One of these things is not like the
others..."


The first two describe a *relationship* between two entities, the name and the
object: being bound to, referring to, are verbs which indicate a relationship.

The third introduces a third entity. There's now two relationships:

- names hold (are bound to, point to) references;

- references refer to (are bound to, point to) objects.

That's an example of reification, "making real", taking an abstract concept or
relationship or verb and treating it as a thing. We often do that in poetic
language: we talk of death or hunger stalking the streets.

In this case, its a bit more complicated because *in a sense* you are right.
Inside the interpreter, there really is a data structure which we might call a
reference: in CPython its a pointer. So you are not entirely being poetic here.
Inside the interpreter, you (probably?) could print out the value of the
pointer, or manipulate it in some fashion.

But at the level of Python code, you are reifying a relationship into a thing.
In Python code, names are bound to objects, and the implementation of that
binding is not part of the language itself. References aren't things, any more
than fatherhood or treason are things (they are states of being that describe a
certain relationships).

That's because Python describes a virtual machine which is abstracted further
away from the machine than C. Part of that abstraction is to remove pointers
(references) from the set of values available to Python code to manipulate.


> These are all equally good ways of talking about 
> the exact same abstract concept.

No they aren't equally good, not if they lead to confusion and terminology
abuse. Earlier I linked to a Stackoverflow question about Java, asking how to
find the address of variables. It must be easy, right, because Java variables
hold pointers to some address. (Actually, no they don't.)

In Python, we still have people asking from time to time how to dereference
pointers (references), or how to pass an int by reference, or a list by value
(making a copy). It must be possible, because Python is pass-by-value for some
values and pass-by-reference for others, right? (No.)

I'm not opposed to the "reference" concept in general. I just want people to be
more clear about what level of abstraction you are talking about when you use
it. I don't want people to say that Python (the language) has references or
pointers, because it doesn't. I don't have any objection to people saying that
the interpreter has references or pointers, and that's how name binding works
behind the scenes, or under the hood.

And I categorically *hate* explanations of Python's argument parsing that
require people to simultaneously believe that the value of x following x=1 is:

1

(the meaning of "value" they actually use in practice), and:

some invisible, unknown, unknowable, implementation-dependent
reference to the actual value

(the meaning they insist 

Re: A question on modification of a list via a function invocation

2017-09-05 Thread Chris Angelico
On Wed, Sep 6, 2017 at 1:42 PM, Stefan Ram  wrote:
> Steve D'Aprano  writes:
>>So in what sense are references part of the Python language?
>
>   It would be possible to describe Python using a concept
>   called "reference", it's just that the The Python Language
>   Reference, Release 3.6.0 (PRL) does /not/ do this.
>   And programming language experts usually use the terms that
>   the language specification uses with the meaning that the
>   language specification is giving them. And this is why I say
>   that JavaScript and Python do not have references.
>   (Except "attribute references".)
>
>>Inside the interpreter, you (probably?) could print out the value of the
>>pointer, or manipulate it in some fashion.
>
>   Well, this /is/ from the PRL:
>
>   »An object's identity never changes once it has been created;
>   you may think of it as the object's address in memory.«.
>  ¯¯
> - The Python Language Reference, Release 3.6.0;
> 3.1 Objects, values and types
>
>   It's not called "reference", it's called "identity". But it
>   might agree with your idea of a pointer of an implementation.
>   And you /can/ print it.
>
 print( id( 'abc' ))
> 4163144

Printing out an address is only half the point (pun intended) of a
pointer - and the useless half. Given a pointer, you need to be able
to dereference it. How can you, given the id of a Python object,
access the object itself? The nearest I've ever seen is a function
that searches every object it can find, looking for one with the same
id.

I *might* be able to accept the argument that pointer arithmetic isn't
important (though I'm still of the opinion that without arithmetic,
they're just references/name bindings), but if you want to say that
the id() of a Python object is its pointer, you MUST demonstrate this
more basic feature.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Rustom Mody
On Wednesday, September 6, 2017 at 9:22:15 AM UTC+5:30, Chris Angelico wrote:
> On Wed, Sep 6, 2017 at 1:42 PM, Stefan Ram wrote:
> > Steve D'Aprano writes:
> >>So in what sense are references part of the Python language?
> >
> >   It would be possible to describe Python using a concept
> >   called "reference", it's just that the The Python Language
> >   Reference, Release 3.6.0 (PRL) does /not/ do this.
> >   And programming language experts usually use the terms that
> >   the language specification uses with the meaning that the
> >   language specification is giving them. And this is why I say
> >   that JavaScript and Python do not have references.
> >   (Except "attribute references".)
> >
> >>Inside the interpreter, you (probably?) could print out the value of the
> >>pointer, or manipulate it in some fashion.
> >
> >   Well, this /is/ from the PRL:
> >
> >   »An object's identity never changes once it has been created;
> >   you may think of it as the object's address in memory.«.
> >  ¯¯
> > - The Python Language Reference, Release 3.6.0;
> > 3.1 Objects, values and types
> >
> >   It's not called "reference", it's called "identity". But it
> >   might agree with your idea of a pointer of an implementation.
> >   And you /can/ print it.
> >
>  print( id( 'abc' ))
> > 4163144
> 
> Printing out an address is only half the point (pun intended) of a
> pointer - and the useless half. Given a pointer, you need to be able
> to dereference it. How can you, given the id of a Python object,
> access the object itself? The nearest I've ever seen is a function
> that searches every object it can find, looking for one with the same
> id.

Well ⅓ the point of pointers may be printing them out — which even in a 
language 
with 1st class pointers like C is rarely done/needed

Another ⅓ is dereferencing, pointer-arithmetic etc... the various manifestations
of 1st-class pointers

And the third ⅓ is to provide explanations to people asking authentic questions
[like the OP of this thread]

Sure you can say with Steven that this can be 'explained' by saying an object
can be in two places at one time.
Others would then say 'Humpty-dumpty!' since you have removed the most basic
intuition of objects and you are in effect saying that a python object
means what you ordain it means without further ado/explanation

Since you believe a reference-less dictionary can be a model for such 
explanations,
why not provide that?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Chris Angelico
On Wed, Sep 6, 2017 at 2:17 PM, Rustom Mody  wrote:
> Well ⅓ the point of pointers may be printing them out — which even in a 
> language
> with 1st class pointers like C is rarely done/needed

But still the useless part. You don't actually *achieve* anything by
printing out the pointer.

> Another ⅓ is dereferencing, pointer-arithmetic etc... the various 
> manifestations
> of 1st-class pointers

This is the part that matters.

> And the third ⅓ is to provide explanations to people asking authentic 
> questions
> [like the OP of this thread]

Only questions that actually relate to one of the previous parts.

> Sure you can say with Steven that this can be 'explained' by saying an object
> can be in two places at one time.
> Others would then say 'Humpty-dumpty!' since you have removed the most basic
> intuition of objects and you are in effect saying that a python object
> means what you ordain it means without further ado/explanation
>
> Since you believe a reference-less dictionary can be a model for such 
> explanations,
> why not provide that?

A piece of paper works just fine. However, it's hard to use that
method of explanation in an email.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Rustom Mody
On Wednesday, September 6, 2017 at 9:55:10 AM UTC+5:30, Chris Angelico wrote:
> On Wed, Sep 6, 2017 at 2:17 PM, Rustom Mody wrote:
> > Well ⅓ the point of pointers may be printing them out — which even in a 
> > language
> > with 1st class pointers like C is rarely done/needed
> 
> But still the useless part. You don't actually *achieve* anything by
> printing out the pointer.
> 
> > Another ⅓ is dereferencing, pointer-arithmetic etc... the various 
> > manifestations
> > of 1st-class pointers
> 
> This is the part that matters.
> 
> > And the third ⅓ is to provide explanations to people asking authentic 
> > questions
> > [like the OP of this thread]
> 
> Only questions that actually relate to one of the previous parts.

[dangling pointer ?¿?¿ ]

> 
> > Sure you can say with Steven that this can be 'explained' by saying an 
> > object
> > can be in two places at one time.
> > Others would then say 'Humpty-dumpty!' since you have removed the most basic
> > intuition of objects and you are in effect saying that a python object
> > means what you ordain it means without further ado/explanation
> >
> > Since you believe a reference-less dictionary can be a model for such 
> > explanations,
> > why not provide that?
> 
> A piece of paper works just fine. However, it's hard to use that
> method of explanation in an email.

I am ready to bet that if ASCII is insufficient then you are drawing pictures

You can call them whatever you like
- pointers, references
- data structure diagrams
- graphs vertices, edges
- I think I'll call them Antoon-art in honor of Antoon Pardon who has the 
  patience to draw them

I believe it was Marko Rauhamaa who have another half dozen metaphors:
- doggies and pussies er.. sorry leashes

Whatever you use, you will have to reify in your explanation the idea of
pointer/graph-edge/etc even and especially because, the language disallows such
a reification
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Steven D'Aprano
On Tue, 05 Sep 2017 18:28:02 -0700, Rustom Mody wrote:

> On Wednesday, September 6, 2017 at 6:27:24 AM UTC+5:30, Steve D'Aprano
> wrote:
>> On Wed, 6 Sep 2017 12:19 am, Rustom Mody wrote:
>> 
>> > And how do you write even the simplest assignment statement without a
>> > (mathematical) expression on the rhs?
>> 
>> name = other_name
>> 
>> is not a mathematical expression. Its giving something a new name.
>> 
>> name = obj.attribute
>> 
>> is not a mathematical expression. (That's not a dot product.)
>> 
>> 
> Ok you win (that)
> [And I see your stocks of straw are overflowing. Wholesale prices?]


A strawman fallacy is not another way of saying "Dammit, you just made a 
counter-argument that I cannot argue against."

On the other hand, false accusations of "strawman" are a form of 
poisoning the well.


As the old legal saying goes:

"When the facts are on your side, argue the facts. When the law is on 
your side, argue the law. When neither are on your side, pound the table."

And when you can't pound the table, accuse your opponent of committing 
the strawman fallacy.


>> > What were Turing, Church, von Neumann, even Knuth by training?
>> > Mathematicians or CS-ists?
>> > 
>> > And what are the contributions of Turing, Church, von Neumann, Knuth
>> > to CS?
>> 
>> Who cares? We're talking about Python, not Computer Science.
> 
> He who forgets history is doomed to repeat it.

I don't forget history, I just know when it is relevant and when it isn't.

Rustom, I don't care if you want to compare Python to mathematics. We 
already know the conclusion: Python is not mathematically pure. That 
doesn't make it wrong.

In fact, I would argue the opposite: by knowing when to bend, or break, 
mathematical purity in favour of more accessible idioms, Python is a 
better language for the majority of people.



> Start with your own statement: “Lisp is a functional language”
[...]
> And most significant: “McCarthy did not consider Lisp to be a functional
> language”

I didn't say it was a *pure* functional language, or a *good* one.


> Of course nothing to be surprised here: You know more java than old
> java-heads And more lisp than John McCarthy 😉

Attacking the man, instead of the argument. Is that the best you've got? 
If you're going to cast aspersions on my character, do it properly: I'm 
an arrogant, ignorant boob who dares to questions the Great Ones who 
clearly are infallible and cannot make a mistake.





-- 
Steven D'Aprano
“You are deluded if you think software engineers who can't write 
operating systems or applications without security holes, can write 
virtualization layers without security holes.” —Theo de Raadt
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Steven D'Aprano
On Wed, 06 Sep 2017 01:31:56 +, Stefan Ram wrote:

> Steve D'Aprano  writes:
>>On Wed, 6 Sep 2017 12:19 am, Rustom Mody wrote:
>>>And how do you write even the simplest assignment statement without a
>>>(mathematical) expression on the rhs?
>>name = other_name is not a mathematical expression. Its giving something
>>a new name.
> 
>   In mathematics, every author is free to give his own definitions to
>   concepts and create his own notation.
[...]
>   Of course, definitions of the form
> 
> x := 2 y := x

Indeed they do. Perhaps I should have said that the Python assignment

name = other_name

is not *necessarily* a mathematical expression, but can also be used to 
give an object a new name.

We can argue whether mathematics has assignment at all, or merely has 
definitions. That's a level of hair-splitting where I'm happy to sit on 
the fence and not give an opinion as to whether the mathematical 
definition:

y = 2

is or is not the same as the Python assignment:

y = 2



-- 
Steven D'Aprano
“You are deluded if you think software engineers who can't write 
operating systems or applications without security holes, can write 
virtualization layers without security holes.” —Theo de Raadt
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Please improve these comprehensions (was meaning of [ ])

2017-09-05 Thread Steven D'Aprano
On Tue, 05 Sep 2017 19:07:32 -0700, Rustom Mody wrote:

> Also noteworthy here: You know more about list comprehensions than their
> inventor — Greg Ewing 

And many people know more about General Relativity than Albert Einstein. 
What's your point?


> [No I normally would not call Greg their inventor

You shouldn't, because he didn't invent them. They existed in Haskell, 
which is where Greg learned about them, and even Haskell did not invent 
them. In fact, Greg merely *proposed* that they be added to Python. He 
didn't write the PEP that specified their behaviour, and the PEP 
specifies behaviour which Greg does not approve of.

Namely that comprehensions are *explicitly* intended as semantically 
equivalent to a for-loop, plus accumulator.

Greg may have been the first to propose comprehensions in Python, but 
that doesn't give him any special insight into their behaviour, and it 
certainly doesn't make him their inventor.


> but in this case following through your logic that python exists in a
> historical, contextual vacuum]

I never said that.



-- 
Steven D'Aprano
“You are deluded if you think software engineers who can't write 
operating systems or applications without security holes, can write 
virtualization layers without security holes.” —Theo de Raadt
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Marko Rauhamaa
Rustom Mody :

> On Wednesday, September 6, 2017 at 3:34:41 AM UTC+5:30, Marko Rauhamaa wrote:
>> Pointer arithmetics is not an essential part of C. One could argue that
>> it was a mistake to include it in the language.
>
> This is subjective of course… but still I wonder where you are coming from…
>
> You of course know that writing Unix was the genesis and raison d'être
> for C right?
>
> And what is an OS but a thin layer of abstraction on top of bare ISP?
> ie is not a Linux-OS just an x86 hw + some new ‘instructions’ called
> system-calls?

BASIC doesn't have any pointers at all, but it has PEEK and POKE.


Marko
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Steven D'Aprano
On Wed, 06 Sep 2017 03:42:31 +, Stefan Ram wrote:

>   Well, this /is/ from the PRL:
> 
>   »An object's identity never changes once it has been created;
>   you may think of it as the object's address in memory.«.
>  ¯¯
> - The Python Language Reference, Release 3.6.0;
> 3.1 Objects, values and types
> 
>   It's not called "reference", it's called "identity". But it might
>   agree with your idea of a pointer of an implementation.
>   And you /can/ print it.
> 
 print( id( 'abc' ))
> 4163144


I just tried that in my handy Python interpreter:


steve@runes:~$ jython
Jython 2.5.3 (, Jun 21 2017, 18:05:17) 
[OpenJDK 64-Bit Server VM (Oracle Corporation)] on java1.7.0_151
Type "help", "copyright", "credits" or "license" for more information.
>>> print id("abcd")
2
>>> print id("abcd")
3
>>> print id(None)
4


Do they look like pointers or references to you? They don't to me. I'm 
not aware of any machine where pointers can point to odd numbers 
(although there probably are some) and I'm certainly not aware of any 
where consecutive pointers differ by 1.


I think the manual is badly worded. It is true that we *can* think of IDs 
as the address of objects in memory, we *shouldn't* because that's 
misleading and tempts the reader to draw the wrong conclusion.

IDs in Python are arbitrary integers. They have no meaning except to be 
distinct for any two objects existing at the same time.



-- 
Steven D'Aprano
“You are deluded if you think software engineers who can't write 
operating systems or applications without security holes, can write 
virtualization layers without security holes.” —Theo de Raadt
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Steven D'Aprano
On Tue, 05 Sep 2017 21:17:30 -0700, Rustom Mody wrote:

> Sure you can say with Steven that this can be 'explained' by saying an
> object can be in two places at one time.
> Others would then say 'Humpty-dumpty!' since you have removed the most
> basic intuition of objects and you are in effect saying that a python
> object means what you ordain it means without further ado/explanation

I have previously agreed that the "multiple places at once" metaphor is 
not to everyone's liking.

But many (perhaps even most) people have no problem dealing with location 
as a metaphor, where being in two places (metaphorically) is no problem 
at all:

- I am in love, in trouble and in denial all at once.

Even when the location is not a state of being but an actual physical 
place, we can be in multiple places at once:

- I am in my home, in Melbourne, and in Australia all at once.

Being in two places at once is a common trope in both fantasy and science 
fiction (often involving time travel). These are not niche genres: they 
are *extremely* popular. One of the Harry Potter movies involved Harry, 
Ron and Hermoine travelling backwards in time a few minutes to watch 
themselves. It's a moderately common trope in stories like Doctor Who, 
where the Doctor frequently interacts with his past (or future) self. I 
recently saw an episode of Dark Matter that used the trope.

Robert Heinlein, one of the greats of SF, wrote a number of classic time 
travel stories involving people being in multiple places at once. (In one 
of them, the protagonist has a sex change and becomes *both* his own 
grandfather and grandmother.)

An object being inside itself is rarer, but its been done at least twice 
that I know of in Doctor Who.

Don't underestimate people's ability to stretch the location metaphor 
beyond actual physical location. We do it all the time for virtual 
locations like IRC channels:

- I'm in #python, #ruby and #javascript all at once.

But if the metaphor isn't for you, I'm not saying you have to use it.



-- 
Steven D'Aprano
“You are deluded if you think software engineers who can't write 
operating systems or applications without security holes, can write 
virtualization layers without security holes.” —Theo de Raadt
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: A question on modification of a list via a function invocation

2017-09-05 Thread Steven D'Aprano
On Wed, 06 Sep 2017 01:04:17 +0300, Marko Rauhamaa wrote:

> Chris Angelico :
> 
>> That shows that the Java '==' operator is like the Python 'is'
>> operator, and checks for object identity. You haven't manipulated
>> pointers at all. In contrast, here's a C program that actually
>> MANIPULATES pointers:
>>
>> [...]
>>
>> You can't do this with Python, since pointer arithmetic fundamentally
>> doesn't exist. You can in C. Can you in Java?

A necessary (but not sufficient) condition to be able to do pointer 
arithmetic is to actually have pointers as a data type.

Pointers are not a data type in either Python or Java, so of course you 
can't do pointer arithmetic on them. If you don't have a pointer, you 
can't do arithmetic on it.

Pointer arithmetic itself is not the issue. Java could have been like 
standard Pascal, and allow pointers as a first class data type (you can 
assign them to variables, pass them to functions, return them, have 
pointers to pointers, etc) without allowing pointer arithmetic. But they 
didn't -- Java the language doesn't include pointers as a value at all.

 
> You can't do it in Pascal, either, but Pascal definitely has pointers.

Not in standard Pascal, but most actual Pascal compilers let you perform 
pointer arithmetic.




-- 
Steven D'Aprano
“You are deluded if you think software engineers who can't write 
operating systems or applications without security holes, can write 
virtualization layers without security holes.” —Theo de Raadt
-- 
https://mail.python.org/mailman/listinfo/python-list