Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91898 > unrolled thread

Can Python function return multiple data?

Started byfl <rxjwg98@gmail.com>
First post2015-06-02 14:27 -0700
Last post2015-06-07 15:33 +1000
Articles 20 on this page of 84 — 22 participants

Back to article view | Back to comp.lang.python


Contents

  Can Python function return multiple data? fl <rxjwg98@gmail.com> - 2015-06-02 14:27 -0700
    Re: Can Python function return multiple data? Joel Goldstick <joel.goldstick@gmail.com> - 2015-06-02 17:35 -0400
    Re: Can Python function return multiple data? sohcahtoa82@gmail.com - 2015-06-02 14:40 -0700
    Re: Can Python function return multiple data? John Gordon <gordon@panix.com> - 2015-06-02 21:40 +0000
    Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-03 09:56 +1000
      Re: Can Python function return multiple data? Thomas Rachel <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de> - 2015-06-03 15:56 +0200
        Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-04 07:35 +1000
        Re: Can Python function return multiple data? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-03 22:56 +0100
          Re: Can Python function return multiple data? sohcahtoa82@gmail.com - 2015-06-03 15:28 -0700
            Re: Can Python function return multiple data? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-06-03 21:30 -0400
            Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-04 11:52 +1000
            Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-04 23:47 +1000
              Re: Can Python function return multiple data? Marko Rauhamaa <marko@pacujo.net> - 2015-06-04 17:25 +0300
                Re: Can Python function return multiple data? Grant Edwards <invalid@invalid.invalid> - 2015-06-04 14:37 +0000
                  Re: Can Python function return multiple data? Marko Rauhamaa <marko@pacujo.net> - 2015-06-04 18:04 +0300
                    Re: Can Python function return multiple data? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-06-04 19:51 -0400
                  Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 03:11 +1000
                    Re: Can Python function return multiple data? Marko Rauhamaa <marko@pacujo.net> - 2015-06-04 20:30 +0300
                      Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 08:37 +1000
                    Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-04 13:30 -0400
                      Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 08:31 +1000
                    Re: Can Python function return multiple data? Grant Edwards <invalid@invalid.invalid> - 2015-06-04 18:38 +0000
                      Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 08:52 +1000
                        Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-05 09:04 +1000
                        Re: Can Python function return multiple data? Grant Edwards <invalid@invalid.invalid> - 2015-06-05 02:02 +0000
                          Re: Can Python function return multiple data? Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-06-05 09:11 +0200
                            Re: Can Python function return multiple data? Marko Rauhamaa <marko@pacujo.net> - 2015-06-05 12:27 +0300
                              Re: Can Python function return multiple data? Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-06-05 14:04 +0200
                    Re: Can Python function return multiple data? BartC <bc@freeuk.com> - 2015-06-04 21:52 +0100
                      Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 09:13 +1000
                        Re: Can Python function return multiple data? BartC <bc@freeuk.com> - 2015-06-05 01:16 +0100
                          Re: Can Python function return multiple data? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-05 02:40 +0100
                            Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 11:48 +1000
                              Re: Can Python function return multiple data? BartC <bc@freeuk.com> - 2015-06-05 11:06 +0100
                    Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-05 07:44 +1000
                  Re: Can Python function return multiple data? BartC <bc@freeuk.com> - 2015-06-05 10:51 +0100
              Re: Can Python function return multiple data? ElChino <elchino@cnn.cn> - 2015-06-04 17:37 +0200
                Re: Can Python function return multiple data? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-06-04 19:57 -0400
              Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-04 13:26 -0400
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 08:16 +1000
                  Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-04 18:59 -0400
                    Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 12:37 +1000
                      Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-04 20:16 -0700
                        Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 21:06 +1000
                          Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-05 06:29 -0700
                            Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-06 07:59 +1000
                              Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-05 20:20 -0700
                                Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-05 23:28 -0400
                                  Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-05 22:28 -0700
                                    Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-06 15:43 +1000
                                      Lawful != Mutable (was Can Python function return multiple data?) Rustom Mody <rustompmody@gmail.com> - 2015-06-07 08:49 -0700
                                        Re: Lawful != Mutable (was Can Python function return multiple data?) Chris Angelico <rosuav@gmail.com> - 2015-06-08 02:07 +1000
                                        Re: Lawful != Mutable (was Can Python function return multiple data?) Rustom Mody <rustompmody@gmail.com> - 2015-06-07 09:20 -0700
                                          Re: Lawful != Mutable (was Can Python function return multiple data?) Chris Angelico <rosuav@gmail.com> - 2015-06-08 02:34 +1000
                                            Re: Lawful != Mutable (was Can Python function return multiple data?) Rustom Mody <rustompmody@gmail.com> - 2015-06-20 18:59 -0700
                                              Re: Lawful != Mutable (was Can Python function return multiple data?) Chris Angelico <rosuav@gmail.com> - 2015-06-21 12:32 +1000
                                                Re: Lawful != Mutable (was Can Python function return multiple data?) Rustom Mody <rustompmody@gmail.com> - 2015-06-20 19:50 -0700
                                                  Re: Lawful != Mutable (was Can Python function return multiple data?) Laura Creighton <lac@openend.se> - 2015-06-21 11:14 +0200
                                                  Re: Lawful != Mutable (was Can Python function return multiple data?) Ron Adam <ron3200@gmail.com> - 2015-06-21 08:55 -0400
                                    Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-07 15:51 +1000
                                Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-06 13:49 +1000
                                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-06 14:50 +1000
                                  Re: Can Python function return multiple data? Chris Angelico <rosuav@gmail.com> - 2015-06-06 15:29 +1000
                                  Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-05 22:32 -0700
                                    Re: Can Python function return multiple data? Dave Farrance <df@see.replyto.invalid> - 2015-06-06 07:52 +0100
                                    Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-07 15:53 +1000
                      Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-05 08:21 -0400
                        Re: Can Python function return multiple data? Marko Rauhamaa <marko@pacujo.net> - 2015-06-05 16:37 +0300
                  Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-04 19:07 -0700
              Re: Can Python function return multiple data? Michael Torrie <torriem@gmail.com> - 2015-06-04 11:36 -0600
              Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-04 13:51 -0400
              Re: Can Python function return multiple data? Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-06-04 20:17 +0200
                Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-05 08:45 +1000
                  Re: Can Python function return multiple data? Alain Ketterlin <alain@universite-de-strasbourg.fr.invalid> - 2015-06-05 08:59 +0200
            Re: Can Python function return multiple data? Michael Torrie <torriem@gmail.com> - 2015-06-04 08:16 -0600
          Re: Can Python function return multiple data? sohcahtoa82@gmail.com - 2015-06-05 11:55 -0700
        Re: Can Python function return multiple data? random832@fastmail.us - 2015-06-04 01:01 -0400
        Re: Can Python function return multiple data? Ian Kelly <ian.g.kelly@gmail.com> - 2015-06-04 12:34 -0600
        Re: Can Python function return multiple data? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-06-04 20:16 +0100
    Re: Can Python function return multiple data? Serhiy Storchaka <storchaka@gmail.com> - 2015-06-04 09:56 +0300
    Re: Can Python function return multiple data? fl <rxjwg98@gmail.com> - 2015-06-06 10:57 -0700
      Re: Can Python function return multiple data? Rustom Mody <rustompmody@gmail.com> - 2015-06-06 21:35 -0700
      Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-07 15:47 +1000
    Re: Can Python function return multiple data? Steven D'Aprano <steve@pearwood.info> - 2015-06-07 15:33 +1000

Page 4 of 5 — ← Prev page 1 2 3 [4] 5  Next page →


#92168

FromChris Angelico <rosuav@gmail.com>
Date2015-06-06 13:49 +1000
Message-ID<mailman.210.1433562594.13271.python-list@python.org>
In reply to#92166
On Sat, Jun 6, 2015 at 1:28 PM,  <random832@fastmail.us> wrote:
> On Fri, Jun 5, 2015, at 23:20, Rustom Mody wrote:
>> The word immutuable happens to have existed in English before python.
>> I also happen to have used it before I knew of python
>> The two meanings do not match
>> I am surprised
>> Is that surprising?
>
> They don't match only if you consider the objects a tuple references to
> be part of the tuple.
>
> You cannot change the reference. It will always point to the same list.

Precisely. I can use indelible ink to write a phone number on a piece
of paper, but that's no guarantee that the same person will always
answer that phone. Doesn't change the indelibility of the writing. If
you want something truly immutable, you have to be careful to
reference only other immutables. In Python, hashability is pretty much
that, but I don't think English has such a concept.

Even if there is a word in English with a slightly different meaning
from its Python meaning, is that so hard to believe? In common usage,
a "dictionary" is something which maps words to their meanings, is
ordered ("dictionary order" being a variant of alphabetical order
which takes into account non-alphabetic characters, diacriticals,
etc), and may have additional information that isn't strictly part of
the mapping. In Python, a "dictionary" is something which maps
hashable values to objects. That's pretty different, but clearly
connected. In many languages, "integer" actually means "integer less
than X" (eg X = 2**32), but people don't complain that that means
they're not integers.

In Python, immutables can contain references to mutables, and the
perceived behaviour of a tuple may be affected by those objects.
They're still immutable.

ChrisA

[toc] | [prev] | [next] | [standalone]


#92169

FromSteven D'Aprano <steve@pearwood.info>
Date2015-06-06 14:50 +1000
Message-ID<55727c1c$0$13000$c3e8da3$5496439d@news.astraweb.com>
In reply to#92166
On Sat, 6 Jun 2015 01:20 pm, Rustom Mody wrote:

> On Saturday, June 6, 2015 at 3:30:23 AM UTC+5:30, Chris Angelico wrote:

>> Congrats! You just proved that an object can itself be immutable, but
>> can contain references to mutables. Ain't that awesome?
>> 
>> Did you have a point?
> 
> [Under assumption you are not being facetious...]
> The word immutuable happens to have existed in English before python.
> I also happen to have used it before I knew of python
> The two meanings do not match
> I am surprised
> Is that surprising?

Yes, I am surprised that you are surprised. You have been a regular, and
prolific, contributor on this forum for some years now, teach Python, blog
about it. You're quite obviously well-read and experienced. How is it that
you are surprised by such a fundamental part of not just Python's object
model, but of real life objects too?

I suspect you are pretending to be surprised to make a rhetorical point.

Like many English words, "immutable" has a few meanings in plain English.
Bouvier's Law Dictionary included in 1856 this definition:

    IMMUTABLE. What cannot be removed, what is unchangeable.
    The laws of God peing perfect, are immutable, but no 
    human law can be so considered.

Clearly tuples can be removed. They are garbage-collected like any other
values in Python. If nothing else, you can turn the computer off, remove
the RAM, grind it down into the finest powder, and scatter it to the winds.
That surely is enough to remove the tuples <wink> 

So according to Bouvier's definition, tuples are not immutable. But I trust
that we can agree that Bouvier's definition is not useful here.

In object-oriented programming circles, including Python, the relevant
definition is that you cannot add or remove elements from the tuple once it
is instantiated. That is all. If those elements happen to be mutable
themselves, they don't cease to be mutable just because you happen to have
put them in a tuple. This does not happen:

    mylist = []
    mytuple = (None, 1, mylist)
    mylist.append(0)
    => raises an exception

The *tuple* is immutable, not the list. The elements of the list are not
elements of the tuple and don't participate in the guarantee of
tuple-immutability.


> As a parallel here is Dijkstra making fun of AI-ers use of the word
> 'intelligent'
>  http://www.cs.utexas.edu/users/EWD/transcriptions/EWD06xx/EWD618.html

Nice rant, but as is typical of so many rants by Dijkstra, it's overflowing
with smugness at his own cleverness, and very light on actual reasoning or
sense.


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#92171

FromChris Angelico <rosuav@gmail.com>
Date2015-06-06 15:29 +1000
Message-ID<mailman.211.1433568557.13271.python-list@python.org>
In reply to#92169
On Sat, Jun 6, 2015 at 2:50 PM, Steven D'Aprano <steve@pearwood.info> wrote:
> This does not happen:
>
>     mylist = []
>     mytuple = (None, 1, mylist)
>     mylist.append(0)
>     => raises an exception
>
> The *tuple* is immutable, not the list.

What you could have is a "FrozenList" (by analogy with frozenset),
something like this:

class FrozenList(tuple):
    def __new__(*a, **kw):
        self = tuple.__new__(*a, **kw)
        hash(self) # If error, disallow construction
        return self

That would raise the error at the moment of mytuple's creation, not at
mylist's mutation, but that's about as close as I can think of to a
"this truly must be immutable" object in Python. And of course, any
object can lie (or be mistaken) about its hashability and mutability:

>>> def adder(x, inc=1): return x+inc
...
>>> hash(adder)
-9223363254790714706
>>> FrozenList((adder,))
(<function adder at 0x7fcbbcf0aae8>,)
>>> descr = {adder: "Add 1 to a number"}

Looks immutable to me.

>>> adder.__defaults__=2,
>>> next(iter(descr))(6)
8

Oops.

ChrisA

[toc] | [prev] | [next] | [standalone]


#92172

FromRustom Mody <rustompmody@gmail.com>
Date2015-06-05 22:32 -0700
Message-ID<afaa02b5-98be-401d-b399-185894c488cb@googlegroups.com>
In reply to#92169
On Saturday, June 6, 2015 at 10:20:49 AM UTC+5:30, Steven D'Aprano wrote:
> On Sat, 6 Jun 2015 01:20 pm, Rustom Mody wrote:
> > As a parallel here is Dijkstra making fun of AI-ers use of the word
> > 'intelligent'
> >  http://www.cs.utexas.edu/users/EWD/transcriptions/EWD06xx/EWD618.html
> 
> Nice rant, but as is typical of so many rants by Dijkstra, it's overflowing
> with smugness at his own cleverness, and very light on actual reasoning or
> sense.

The cleverness and smugness has made you miss the point:
Post-computers 'intelligent' has a new meaning on account of abuse of langauge

[toc] | [prev] | [next] | [standalone]


#92175

FromDave Farrance <df@see.replyto.invalid>
Date2015-06-06 07:52 +0100
Message-ID<8155na90ll2vr6lnhppn19fo9vovrnmcrr@4ax.com>
In reply to#92172
Rustom Mody <rustompmody@gmail.com> wrote:

>On Saturday, June 6, 2015 at 10:20:49 AM UTC+5:30, Steven D'Aprano wrote:
>> On Sat, 6 Jun 2015 01:20 pm, Rustom Mody wrote:
>> > As a parallel here is Dijkstra making fun of AI-ers use of the word
>> > 'intelligent'
>> >  http://www.cs.utexas.edu/users/EWD/transcriptions/EWD06xx/EWD618.html
>> 
>> Nice rant, but as is typical of so many rants by Dijkstra, it's overflowing
>> with smugness at his own cleverness, and very light on actual reasoning or
>> sense.
>
>The cleverness and smugness has made you miss the point:
>Post-computers 'intelligent' has a new meaning on account of abuse of langauge

Hmm.  I've just read that and I have to say that I've no idea what point
the author was trying to make -- presumably because I'm not intelligent
enough.  I get that he's doing his best to make "Artificial
Intelligentsia" a pejorative term for some reason, but exactly what he's
got against this (imagined?) community or exactly what he imagines their
sin to be is hard to figure out.  I'll note that my own observation of
the common usage of the term "intelligent" in the mentioned context is
that you might indeed describe a terminal an "intelligent terminal" if
it has processor functions, but if you were to describe it as a
"terminal with artificial intelligence", then that would imply a whole
lot more -- which is indeed a language oddity, but that seems to be the
way it is now.

[toc] | [prev] | [next] | [standalone]


#92203

FromSteven D'Aprano <steve@pearwood.info>
Date2015-06-07 15:53 +1000
Message-ID<5573dc6a$0$12997$c3e8da3$5496439d@news.astraweb.com>
In reply to#92172
On Sat, 6 Jun 2015 03:32 pm, Rustom Mody wrote:

> On Saturday, June 6, 2015 at 10:20:49 AM UTC+5:30, Steven D'Aprano wrote:
>> On Sat, 6 Jun 2015 01:20 pm, Rustom Mody wrote:
>> > As a parallel here is Dijkstra making fun of AI-ers use of the word
>> > 'intelligent'
>> >  http://www.cs.utexas.edu/users/EWD/transcriptions/EWD06xx/EWD618.html
>> 
>> Nice rant, but as is typical of so many rants by Dijkstra, it's
>> overflowing with smugness at his own cleverness, and very light on actual
>> reasoning or sense.
> 
> The cleverness and smugness has made you miss the point:
> Post-computers 'intelligent' has a new meaning on account of abuse of
> langauge

Why do you think it is abuse of language?

The Oxford dictionary lists eight related but distinct meanings for
intelligence and seven for intelligent. Here is the definition from
Websters that Dijkstra rails against:

    able to perform some of the functions of a computer 
    <an ~ computer terminal>.


The Oxford dictionary describes a similar definition in more detail:

    Of a device, system or machine; able to vary its behaviour
    in response to varying situations, requirements, and past
    experience; spec. (esp. of a computer terminal) having its
    own data-processing capability, incorporating a microprocessor.


Clearly the meaning relates to dumb terminals versus intelligent terminals:
the dumb terminal is unable to vary its own behaviour in response to the
environment, but is reliant on a computer elsewhere, while the intelligent
terminal is able to vary its own behaviour and can perform some of the
functions of a computer. A perfectly sensible (even, dare I say it,
intelligent) meaning of the word.

Far from being an abuse of language, this is exactly the sort of thing that
language is made for.



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#92136

Fromrandom832@fastmail.us
Date2015-06-05 08:21 -0400
Message-ID<mailman.194.1433506919.13271.python-list@python.org>
In reply to#92118
On Thu, Jun 4, 2015, at 22:37, Steven D'Aprano wrote:

> That's not a reference to the value. That's a string that describes the
> object.

Well, of course. None of these things are strings.

The normal human-readable representation of a reference is an arrow on a
diagram, pointing from a box that represents the variable to a box that
represents the object. But I can't exactly put that in a text-based
email.

[toc] | [prev] | [next] | [standalone]


#92147

FromMarko Rauhamaa <marko@pacujo.net>
Date2015-06-05 16:37 +0300
Message-ID<87bngu46on.fsf@elektro.pacujo.net>
In reply to#92136
random832@fastmail.us:

> The normal human-readable representation of a reference is an arrow on
> a diagram, pointing from a box that represents the variable to a box
> that represents the object. But I can't exactly put that in a
> text-based email.

An *lvalue* is anything that can be assigned to:

   x = 3
   a[3] = 2
   d['hello'] = 'world'

An *rvalue* is anything that can be assigned to an lvalue.

In Python, every rvalue is a *reference* to an *object*.

So your first box is an lvalue, your arrow is an rvalue and your second
box is an object.

The words "lvalue" and "rvalue" smell like C, so Python people tend to
want to find loftier terms at the expense of clarity. Thus instead of
saying,

    The lvalue contains a reference to an object.

they prefer saying,

    The reference is bound to an object.

Unfortunately, that practice renders the meaning of a "reference"
ambiguous.


Marko

[toc] | [prev] | [next] | [standalone]


#92115

FromRustom Mody <rustompmody@gmail.com>
Date2015-06-04 19:07 -0700
Message-ID<586cafa7-1e9b-4199-acec-0c2bb36bbb54@googlegroups.com>
In reply to#92094
On Friday, June 5, 2015 at 3:46:47 AM UTC+5:30, Steven D'Aprano wrote:
> On Fri, 5 Jun 2015 03:26 am, random832 wrote:
> > If the value really were 23, the "is vs ==" problem wouldn't exist.
> 
> What "problem"? "is versus ==" is not a problem, it is a feature. The two
> operators do two different things.
> 
> But I am *astonished* that you think that the value of x after x = 23 is not
> 23. If it's not 23, then what is it?
> 
> (Actually, I'm not that astonished. There are some kinds of foolishness that
> only really smart people can fall for.)

Yeah some rather smart people... 

http://en.wikipedia.org/wiki/BLISS#Language_description
[See the part on 'reference to a variable']
In C in
x = y
x is l-value y is r-value and the choice of which attribute to select is
context-sensitive.
In this regimen it is uniform and straightforward, variable only ever
means l-value. r-value is obtained with a dot-operator '.x'
So the usual C's
x = y
in Bliss is 
x = .y

[BTW the lead to the wikipedia article describes Bliss as the best known
system programming language till C made its debut]

Also I believe Algol-68 similarly uniformed variable refs but in the opposite
direction [if I understand it right]
C's
x = y
becomes in Algol-68
ref x := y
[Admittedly the Algol-68 docs are too dense for me so I may be misunderstanding]

In any case my points

1. C's context sensitive variables is quite strange.
Even if (in 2015) its the universally acceptped norm there were more
intelligent/intelligible times...

2. If you think is vs == is not a problem, you are not paying attention to the
repeated arguments/confusions around that subject

[The cognoscenti argue, the ignoramuses are confused. Its probably the other
way round -- the ignorants' displayed confusion probably indicates the cognoscenti's real confusion

3. Functional programming choice to throw the baby out with the bathwater
-- no assignment, no mutation -- is extreme but not unfounded

[toc] | [prev] | [next] | [standalone]


#92077

FromMichael Torrie <torriem@gmail.com>
Date2015-06-04 11:36 -0600
Message-ID<mailman.170.1433439422.13271.python-list@python.org>
In reply to#92052
On 06/04/2015 11:26 AM, random832@fastmail.us wrote:
> Of course, in CPython, the type of an object reference is PyObject *.
> Which isn't invisible, unknown, or unknowable, either.
> 
> If the value really were 23, the "is vs ==" problem wouldn't exist.

Surely two objects can hold the same value, or represent the same value
(number), without *having* to be the same object.  I don't see why
people would assume, let alone demand that different objects
representing the same value be the same actual object.  Why should it
even matter? Just relax and write code.  I enjoy the forays into the the
technical, and even the pedantic, but this is getting a bit silly.


> x = 500
> y = x+1
> z = y-1
> 
> x and z (probably) point to two different objects.

Sure.  Python does not require objects representing numeric values to be
singletons.  And why worry anyway?  The "is" operator is to be used in
specific cases where identity is important (it's not important in the
case of numbers).

I'm sure an interpreter implementation could always guarantee that any
object representing an integer value is always the same one, if a person
thought it would make things faster.  And in fact cpython does inter
small values.  But given that the interpreter is computing an actual,
binary value under the hood during calculations, I can understand why
it's just as easy to wrap up the answer in an object and hand it back to
you, rather than try to guarantee a reference to an existing object of
the same value.

[toc] | [prev] | [next] | [standalone]


#92081

Fromrandom832@fastmail.us
Date2015-06-04 13:51 -0400
Message-ID<mailman.171.1433440311.13271.python-list@python.org>
In reply to#92052
On Thu, Jun 4, 2015, at 13:36, Michael Torrie wrote:
> Surely two objects can hold the same value, or represent the same value
> (number), without *having* to be the same object.  I don't see why
> people would assume, let alone demand that different objects
> representing the same value be the same actual object.  Why should it
> even matter? Just relax and write code.  I enjoy the forays into the the
> technical, and even the pedantic, but this is getting a bit silly.

I think I've solved the terminology problem...

it's call-by-value, but the value of a variable, or an argument, or an
expression, is not the value of the object, but rather it is the object
(or, if you like, the id of the object.)

So it's call-by-value where the object is the value that is _really_
passed in. "The value of an object" is simply an equivalence
relationship (so, the value of [1, 2] is the same as the value of [1, 2]
until one of them changes) defined by the hash and == operators of the
object's class rather than having any meaning to the language.

Imagine you have a, b = [1, 2], [1, 2]. If a and b had the same value,
then you could substitute them - a[0] = 3 would have the same effect as
b[0] = 3.

Immutable objects confuse this, because there aren't any operations you
can do to one that would cause its value to be different from another
one that once had the same value, so people think the value of the
variable is the value of the object rather than the value of the
variable being *the object*.

[toc] | [prev] | [next] | [standalone]


#92083

FromAlain Ketterlin <alain@universite-de-strasbourg.fr.invalid>
Date2015-06-04 20:17 +0200
Message-ID<87r3prjq36.fsf@universite-de-strasbourg.fr.invalid>
In reply to#92052
Steven D'Aprano <steve@pearwood.info> writes:

[...]
> But you still find a few people here and there who have been exposed to Java
> foolishness, and will argue that Python is "pass by value, where the value
> is an implementation dependent reference to the thing that you thought was
> the value".

I find this clear and concise. Can you exhibit an example that would not
match this description?

> In other words, according to this Java philosophy, following `x = 23`, the
> value of x is not 23 like any sane person would expect, but some invisible
> and unknown, and unknowable, reference to 23.

No, Java doesn't work like that for primitive types (assuming that by
"Java" you mean the language and execution environment defined in
reference documents).

-- Alain.

[toc] | [prev] | [next] | [standalone]


#92097

FromSteven D'Aprano <steve@pearwood.info>
Date2015-06-05 08:45 +1000
Message-ID<5570d51a$0$13002$c3e8da3$5496439d@news.astraweb.com>
In reply to#92083
On Fri, 5 Jun 2015 04:17 am, Alain Ketterlin wrote:

> Steven D'Aprano <steve@pearwood.info> writes:
> 
> [...]
>> But you still find a few people here and there who have been exposed to
>> Java foolishness, and will argue that Python is "pass by value, where the
>> value is an implementation dependent reference to the thing that you
>> thought was the value".
> 
> I find this clear and concise. Can you exhibit an example that would not
> match this description?
> 
>> In other words, according to this Java philosophy, following `x = 23`,
>> the value of x is not 23 like any sane person would expect, but some
>> invisible and unknown, and unknowable, reference to 23.
> 
> No, Java doesn't work like that for primitive types (assuming that by
> "Java" you mean the language and execution environment defined in
> reference documents).

Perhaps the fact that I used Python syntax was too ambiguous <wink> but I
was talking about Python. However, the same applies to Java, if you
substitute an object for the primitive value:

    Integer x = new Integer(23);

According to the Java philosophy, the value of x is not the object
Integer(23) like any sane person would expect, but some invisible and
unknown reference to that object.

Clear now?



-- 
Steven

[toc] | [prev] | [next] | [standalone]


#92125

FromAlain Ketterlin <alain@universite-de-strasbourg.fr.invalid>
Date2015-06-05 08:59 +0200
Message-ID<87mw0ek5cl.fsf@universite-de-strasbourg.fr.invalid>
In reply to#92097
Steven D'Aprano <steve@pearwood.info> writes:

> On Fri, 5 Jun 2015 04:17 am, Alain Ketterlin wrote:
>
>> Steven D'Aprano <steve@pearwood.info> writes:
>> 
>> [...]
>>> But you still find a few people here and there who have been exposed to
>>> Java foolishness, and will argue that Python is "pass by value, where the
>>> value is an implementation dependent reference to the thing that you
>>> thought was the value".
>> 
>> I find this clear and concise. Can you exhibit an example that would not
>> match this description?
>> 
>>> In other words, according to this Java philosophy, following `x = 23`,
>>> the value of x is not 23 like any sane person would expect, but some
>>> invisible and unknown, and unknowable, reference to 23.
>> 
>> No, Java doesn't work like that for primitive types (assuming that by
>> "Java" you mean the language and execution environment defined in
>> reference documents).
>
> Perhaps the fact that I used Python syntax was too ambiguous <wink> but I
> was talking about Python. However, the same applies to Java, if you
> substitute an object for the primitive value:
>
>     Integer x = new Integer(23);
>
> According to the Java philosophy, the value of x is not the object
> Integer(23) like any sane person would expect,

Yes, clear (except for sanity).

> but some invisible and unknown reference to that object.

I think Python does exactly this (Grant Edwards has a good explanation
of it els ethread).

At least, that is how I understand it, and that is how I teach it, and I
have never met a single case where it failed to describe and explain the
actual behavior of the program.

That's why I was asking for an example to motivate your claim on sanity.

-- Alain.

[toc] | [prev] | [next] | [standalone]


#92058

FromMichael Torrie <torriem@gmail.com>
Date2015-06-04 08:16 -0600
Message-ID<mailman.164.1433427425.13271.python-list@python.org>
In reply to#92008
On 06/03/2015 04:28 PM, sohcahtoa82@gmail.com wrote:

> 
> People actually argue that Python passes by value?  This is easily
> proven wrong by passing a mutable object to a function and changing
> it within the function.

Sure but if you reassign the variable that was passed it, it has no
effect whatsoever on the caller's variable, mutable or not.  This is why
people argue for "pass by value."  Because of this confusion, we often
say, "pass by object."

For example

def foo(bar):
    bar.append(5)
    bar = 6 #bar is no longer referring to a list

a=[1,2,3,4]
foo(a)
print (a)
# prints [1,2,3,4,5]





[toc] | [prev] | [next] | [standalone]


#92161

Fromsohcahtoa82@gmail.com
Date2015-06-05 11:55 -0700
Message-ID<b2b259e5-7c0c-4c2a-bd2b-7eea960db673@googlegroups.com>
In reply to#92004
On Wednesday, June 3, 2015 at 2:57:00 PM UTC-7, Mark Lawrence wrote:
> On 03/06/2015 22:35, Chris Angelico wrote:
> > On Wed, Jun 3, 2015 at 11:56 PM, Thomas Rachel
> > <nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915@spamschutz.glglgl.de>
> > wrote:
> >> Am 03.06.2015 um 01:56 schrieb Chris Angelico:
> >>
> >>> and it's pretty convenient. In C, the nearest equivalent is passing a
> >>> number of pointers as parameters, and having the function fill out
> >>> values. Python's model is a lot closer to what you're saying than C's
> >>> model is :)
> >>
> >>
> >> At least, C functions can return structs...
> >
> > Oh, yes, I forgot about that. Thought that was C++ but not C, partly
> > because I never do it in either language. Although in a sense, a
> > struct is still a single "thing".
> >
> > ChrisA
> >
> 
> Don't forget that C functions can accept structs as input.  Possibly not 
> a good idea as I found out many years ago pre ANSIC when I forgot that 
> little old ampersand, so the compiler didn't pick it up, but then with 
> modern computers having so much memory who really cares if you burn a 
> little bit of stack on structures rather than pointers to structures?
> 
> Now does Python pass by value or by reference?  Happily sits back and 
> waits for 10**6 emails to arrive as this is discussed for the 10**6th time.
> 
> -- 
> My fellow Pythonistas, ask not what our language can do for you, ask
> what you can do for our language.
> 
> Mark Lawrence

Boy, you really called it on the 10**6 emails thing.  This thread certainly exploded.

[toc] | [prev] | [next] | [standalone]


#92027

Fromrandom832@fastmail.us
Date2015-06-04 01:01 -0400
Message-ID<mailman.143.1433394118.13271.python-list@python.org>
In reply to#91966
On Wed, Jun 3, 2015, at 17:56, Mark Lawrence wrote:
> Now does Python pass by value or by reference?  Happily sits back and 
> waits for 10**6 emails to arrive as this is discussed for the 10**6th
> time.

Python's in that same awkward space as Java, where it technically passes
by value, but the values are usually pointers, so passing a mutable
object (such as a list) allows the function to modify the caller's state
in a way that many people associate exclusively with by-reference.

Have I hit all the high points?

[toc] | [prev] | [next] | [standalone]


#92084

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-06-04 12:34 -0600
Message-ID<mailman.172.1433442898.13271.python-list@python.org>
In reply to#91966
On Wed, Jun 3, 2015 at 3:56 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
> Now does Python pass by value or by reference?  Happily sits back and waits
> for 10**6 emails to arrive as this is discussed for the 10**6th time.

Troll.

[toc] | [prev] | [next] | [standalone]


#92088

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2015-06-04 20:16 +0100
Message-ID<mailman.175.1433445431.13271.python-list@python.org>
In reply to#91966
On 04/06/2015 19:34, Ian Kelly wrote:
> On Wed, Jun 3, 2015 at 3:56 PM, Mark Lawrence <breamoreboy@yahoo.co.uk> wrote:
>> Now does Python pass by value or by reference?  Happily sits back and waits
>> for 10**6 emails to arrive as this is discussed for the 10**6th time.
>
> Troll.
>

True indeed.

As expected the "pass by value" versus the "pass by reference" brigade 
have come out of the stalls running very strongly, but as always the 
"pass by object" crew have arrived very late on the stand side and look 
as if they will win by a nose, unless a photo finish is called in which 
case there is a stewards' enquiry.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#92033

FromSerhiy Storchaka <storchaka@gmail.com>
Date2015-06-04 09:56 +0300
Message-ID<mailman.146.1433401017.13271.python-list@python.org>
In reply to#91898
On 03.06.15 02:56, Chris Angelico wrote:
> On Wed, Jun 3, 2015 at 7:27 AM, fl <rxjwg98@gmail.com> wrote:
>> I just see the tutorial says Python can return value in function, it does
>> not say multiple data results return situation. In C, it is possible.
>> How about Python on a multiple data return requirement?
>
> Technically, neither C nor Python can return multiple values from a
> single function call. In Python, the most common way to do this is to
> return a tuple, which can then be unpacked; as other posts in this
> thread have shown, this can look a lot like returning multiple values,
> and it's pretty convenient. In C, the nearest equivalent is passing a
> number of pointers as parameters, and having the function fill out
> values. Python's model is a lot closer to what you're saying than C's
> model is :)

Closer modeling of C's model in python is to pass an object or a list as 
an argument and set their attributes or elements in the function.

def f(a, b):
     a.x = 4.3
     a.y = 1.7
     b[:] = [45, 67]
     return 3

[toc] | [prev] | [next] | [standalone]


Page 4 of 5 — ← Prev page 1 2 3 [4] 5  Next page →

Back to top | Article view | comp.lang.python


csiph-web