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


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

What is a function parameter =[] for?

Started byfl <rxjwg98@gmail.com>
First post2015-11-18 13:08 -0800
Last post2015-11-25 03:11 +1100
Articles 20 on this page of 198 — 24 participants

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


Contents

  What is a function parameter =[] for? fl <rxjwg98@gmail.com> - 2015-11-18 13:08 -0800
    Re: What is a function parameter =[] for? John Gordon <gordon@panix.com> - 2015-11-18 22:05 +0000
    Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-18 15:11 -0700
      Re: What is a function parameter =[] for? Grant Edwards <invalid@invalid.invalid> - 2015-11-18 22:33 +0000
      Re: What is a function parameter =[] for? fl <rxjwg98@gmail.com> - 2015-11-18 14:38 -0800
        Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-18 15:47 -0700
        Re: What is a function parameter =[] for? fl <rxjwg98@gmail.com> - 2015-11-18 14:48 -0800
      Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-18 23:14 +0000
        Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-19 10:22 +1100
          Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-19 01:41 +0000
            Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-19 12:59 +1100
              Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-19 11:41 +0000
                Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-19 22:58 +1100
                Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-19 23:45 +1100
                  Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-19 08:42 -0700
                    Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-22 14:58 +1100
                  Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 13:38 +0100
                    Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-25 04:29 +1100
            Re: What is a function parameter =[] for? Ben Finney <ben+python@benfinney.id.au> - 2015-11-19 13:08 +1100
            Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-19 13:15 +1100
        Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-18 17:02 -0700
        Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-19 11:14 +1100
          Re: What is a function parameter =[] for? fl <rxjwg98@gmail.com> - 2015-11-18 16:34 -0800
            Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-18 17:52 -0700
            Re: What is a function parameter =[] for? MRAB <python@mrabarnett.plus.com> - 2015-11-19 01:02 +0000
            Re: What is a function parameter =[] for? Ben Finney <ben+python@benfinney.id.au> - 2015-11-19 12:26 +1100
            Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-19 22:38 +1100
        Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-19 23:19 +1100
          Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-19 13:19 +0000
            Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-20 00:45 +1100
            Re: What is a function parameter =[] for? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-19 09:05 -0500
            Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-20 03:01 +1100
              Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-20 04:30 +1100
              Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-19 17:30 +0000
                Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-20 04:45 +1100
                  Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-19 18:19 +0000
                    Re: What is a function parameter =[] for? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-11-19 18:26 +0000
                      Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-19 18:50 +0000
                        Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-20 06:09 +1100
                          Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-19 19:48 +0000
                            Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-20 06:58 +1100
                        Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-20 11:26 +1100
                          Re: What is a function parameter =[] for? Ned Batchelder <ned@nedbatchelder.com> - 2015-11-19 16:36 -0800
                            Re: What is a function parameter =[] for? Laura Creighton <lac@openend.se> - 2015-11-20 02:00 +0100
                          Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-19 17:59 -0700
                    Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-19 20:39 +0200
                    Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-19 11:42 -0700
                    Re: What is a function parameter =[] for? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-11-19 18:44 +0000
                    Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-20 06:19 +1100
                      Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-19 21:21 +0000
                        Re: What is a function parameter =[] for? Michael Torrie <torriem@gmail.com> - 2015-11-19 15:55 -0700
                          Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-20 00:11 +0000
                            Re: What is a function parameter =[] for? Ned Batchelder <ned@nedbatchelder.com> - 2015-11-19 16:27 -0800
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 14:43 +0100
                              Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-25 01:00 +1100
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 15:24 +0100
                              Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-25 01:34 +1100
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 16:01 +0100
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 16:03 +0100
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 16:12 +0100
                              Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-25 02:17 +1100
                                Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-25 04:54 +1100
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 16:46 +0100
                              Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-25 02:48 +1100
                              Re: What is a function parameter =[] for? Random832 <random832@fastmail.com> - 2015-11-24 16:28 +0000
                              Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-25 03:38 +1100
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 17:41 +0100
                              Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-24 09:56 -0700
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 18:32 +0100
                              Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-24 10:53 -0700
                              Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-24 11:04 -0700
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 19:45 +0100
                                Re: What is a function parameter =[] for? Ned Batchelder <ned@nedbatchelder.com> - 2015-11-24 10:54 -0800
                              Re: What is a function parameter =[] for? Random832 <random832@fastmail.com> - 2015-11-24 19:00 +0000
                                Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-25 11:34 +1100
                              Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-24 12:15 -0700
                              Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-24 12:15 -0700
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 21:54 +0100
                                Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-24 21:14 +0000
                                  Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 22:25 +0100
                                    Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-25 11:36 +1100
                                      Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-25 11:56 +1100
                                      Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-25 10:56 +0100
                                        Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-26 04:40 +1100
                                          Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-25 19:27 +0100
                                            Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-26 11:10 +1100
                                          Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-25 13:39 -0700
                                          Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-25 22:05 +0100
                                          Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-26 09:06 +1100
                                          Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-25 15:38 -0700
                                          Re: What is a function parameter =[] for? Alan Bawden <alan@csail.mit.edu> - 2015-11-25 21:08 -0500
                                            Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-26 13:25 +1100
                                              Re: What is a function parameter =[] for? Alan Bawden <alan@csail.mit.edu> - 2015-11-25 23:27 -0500
                                                Re: What is a function parameter =[] for? Dave Farrance <df@see.replyto.invalid> - 2015-11-26 10:34 +0000
                                                  Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-26 12:58 +0200
                                                    Re: What is a function parameter =[] for? Dave Farrance <df@see.replyto.invalid> - 2015-11-26 11:12 +0000
                                                      Object identity has no necessary connection to memory location (was: What is a function parameter =[] for?) Ben Finney <ben+python@benfinney.id.au> - 2015-11-26 22:24 +1100
                                                        Re: Object identity has no necessary connection to memory location (was: What is a function parameter =[] for?) Dave Farrance <df@see.replyto.invalid> - 2015-11-26 11:50 +0000
                                                          Re: Object identity has no necessary connection to memory location Ben Finney <ben+python@benfinney.id.au> - 2015-11-27 07:00 +1100
                                                            Re: Object identity has no necessary connection to memory location Steven D'Aprano <steve@pearwood.info> - 2015-11-27 13:17 +1100
                                                          Re: Object identity has no necessary connection to memory location Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-11-26 21:44 +0000
                                                      Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-26 22:24 +1100
                                                      Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-26 13:27 +0200
                                                      Re: Object identity has no necessary connection to memory location (was: What is a function parameter =[] for?) Chris Angelico <rosuav@gmail.com> - 2015-11-26 22:49 +1100
                                                      Re: Object identity has no necessary connection to memory location Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-26 13:04 +0100
                                                  Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-27 12:34 +1100
                                                    Re: What is a function parameter =[] for? Ben Finney <ben+python@benfinney.id.au> - 2015-11-27 12:40 +1100
                                                      Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-27 13:44 +1100
                                                        Re: What is a function parameter =[] for? MRAB <python@mrabarnett.plus.com> - 2015-11-27 02:56 +0000
                                                          Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-27 23:57 +1100
                                                            Re: What is a function parameter =[] for? Laura Creighton <lac@openend.se> - 2015-11-27 14:24 +0100
                                                            Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-28 00:29 +1100
                                                        Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-27 14:06 +1100
                                                        Re: What is a function parameter =[] for? Ben Finney <ben+python@benfinney.id.au> - 2015-11-27 15:56 +1100
                                                    Re: What is a function parameter =[] for? Random832 <random832@fastmail.com> - 2015-11-26 23:33 -0500
                                            Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-25 19:46 -0700
                                            Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-26 14:02 +1100
                                          Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-26 09:15 +0100
                              Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-24 14:33 -0700
                              Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-25 09:09 +1100
                    Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-19 12:25 -0700
                Re: What is a function parameter =[] for? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-11-19 18:20 +0000
                Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-20 12:05 +1100
                  Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-20 11:59 +0000
                    Re: What is a function parameter =[] for? Ned Batchelder <ned@nedbatchelder.com> - 2015-11-20 04:12 -0800
                      Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-20 12:39 +0000
                        Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-21 00:04 +1100
                        Re: What is a function parameter =[] for? Ned Batchelder <ned@nedbatchelder.com> - 2015-11-20 05:30 -0800
                        Re: What is a function parameter =[] for? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-20 08:34 -0500
                        Re: What is a function parameter =[] for? Random832 <random832@fastmail.com> - 2015-11-20 14:32 +0000
                        Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-20 09:18 -0700
                        Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-22 23:01 +1100
                        Re: What is a function parameter =[] for? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-23 12:30 +1300
                        Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 15:38 +0100
                      Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 15:34 +0100
                        Re: What is a function parameter =[] for? Ned Batchelder <ned@nedbatchelder.com> - 2015-11-24 06:50 -0800
                      Re: What is a function parameter =[] for? Terry Reedy <tjreedy@udel.edu> - 2015-11-24 12:46 -0500
                      Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 19:27 +0100
                    Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-20 14:28 +0200
                      Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-20 12:53 +0000
                        Re: What is a function parameter =[] for? Random832 <random832@fastmail.com> - 2015-11-20 14:35 +0000
                        Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-22 21:06 +1100
                          Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-22 14:35 +0200
                      Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-20 09:16 -0700
                        Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-20 18:31 +0200
                          Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-21 03:37 +1100
                          Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-20 09:39 -0700
                      Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-21 03:24 +1100
                      Re: What is a function parameter =[] for? Ian Kelly <ian.g.kelly@gmail.com> - 2015-11-20 09:29 -0700
                        Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-20 18:41 +0200
                      Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-21 03:36 +1100
                    Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-22 14:43 +1100
                      Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-22 13:21 +0000
                        Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-22 14:28 +0000
                        Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-23 10:44 +1100
                          Re: What is a function parameter =[] for? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-11-23 00:04 +0000
                            Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-23 00:37 +0000
                              Re: What is a function parameter =[] for? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-11-23 11:32 +0000
                                Re: What is a function parameter =[] for? Ned Batchelder <ned@nedbatchelder.com> - 2015-11-23 04:05 -0800
                              Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-23 14:23 +0200
                          Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-23 11:20 +1100
                      Re: What is a function parameter =[] for? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2015-11-23 12:43 +1300
                        Re: What is a function parameter =[] for? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-11-23 18:47 +1100
                          Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-23 10:40 +0000
                            Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-24 00:58 +1100
                              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 15:58 +0100
                                Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-25 04:56 +1100
                  Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 15:18 +0100
                Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 14:48 +0100
        Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 12:36 +0100
        Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-24 23:07 +1100
        Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 13:48 +0100
          Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-24 14:57 +0200
            Re: What is a function parameter =[] for? Ned Batchelder <ned@nedbatchelder.com> - 2015-11-24 06:18 -0800
              Re: What is a function parameter =[] for? BartC <bc@freeuk.com> - 2015-11-24 14:43 +0000
                Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-25 01:54 +1100
              Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-24 16:10 +0100
                Re: What is a function parameter =[] for? Ned Batchelder <ned@nedbatchelder.com> - 2015-11-24 07:27 -0800
                  Re: What is a function parameter =[] for? Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2015-11-24 17:25 +0000
                    Re: What is a function parameter =[] for? Ned Batchelder <ned@nedbatchelder.com> - 2015-11-24 09:35 -0800
                      Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-24 20:13 +0200
                        Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-25 05:33 +1100
                          Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-24 21:17 +0200
              Re: What is a function parameter =[] for? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2015-11-24 11:27 -0500
              Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-25 11:39 +1100
                Re: What is a function parameter =[] for? Laura Creighton <lac@openend.se> - 2015-11-25 01:55 +0100
                A name refers to an object, an object has a value, equality compares values (was: What is a function parameter =[] for?) Ben Finney <ben+python@benfinney.id.au> - 2015-11-25 13:17 +1100
                  Re: A name refers to an object, an object has a value, equality compares values Marko Rauhamaa <marko@pacujo.net> - 2015-11-25 08:44 +0200
                    Re: A name refers to an object, an object has a value, equality compares values Chris Angelico <rosuav@gmail.com> - 2015-11-25 19:27 +1100
                Re: What is a function parameter =[] for? Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-11-25 10:36 +0100
                  Re: What is a function parameter =[] for? Jussi Piitulainen <harvest@should.be.invalid> - 2015-11-25 13:39 +0200
                    Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-25 14:48 +0200
                      Re: What is a function parameter =[] for? Chris Angelico <rosuav@gmail.com> - 2015-11-26 00:50 +1100
                        Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-25 16:08 +0200
                      Re: What is a function parameter =[] for? Jussi Piitulainen <harvest@should.be.invalid> - 2015-11-25 17:13 +0200
                        Re: What is a function parameter =[] for? Marko Rauhamaa <marko@pacujo.net> - 2015-11-25 18:44 +0200
                          Re: What is a function parameter =[] for? Jussi Piitulainen <harvest@should.be.invalid> - 2015-11-25 20:30 +0200
            Re: What is a function parameter =[] for? Steven D'Aprano <steve@pearwood.info> - 2015-11-25 03:11 +1100

Page 1 of 10  [1] 2 3 … 10  Next page →


#98999 — What is a function parameter =[] for?

Fromfl <rxjwg98@gmail.com>
Date2015-11-18 13:08 -0800
SubjectWhat is a function parameter =[] for?
Message-ID<d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com>
Hi,

I have tried the below function and find that it can remember the previous
setting value to 'val'. I think the second parameter has something on this 
effect, but I don't know the name and function of '=[]' in this application.

Could you explain a little to me?
Thanks,


def eList(val, list0=[]):
    list0.append(val)
    return list0
list1 = eList(12)
list1 = eList('a')

[toc] | [next] | [standalone]


#99002

FromJohn Gordon <gordon@panix.com>
Date2015-11-18 22:05 +0000
Message-ID<n2ismv$jdd$1@reader1.panix.com>
In reply to#98999
In <d9045bdd-a5d4-4c5c-9fd3-3d54f6b50862@googlegroups.com> fl <rxjwg98@gmail.com> writes:

> Hi,

> I have tried the below function and find that it can remember the previous
> setting value to 'val'. I think the second parameter has something on this 
> effect, but I don't know the name and function of '=[]' in this application.

> Could you explain a little to me?
> Thanks,

> def eList(val, list0=[]):
>     list0.append(val)
>     return list0
> list1 = eList(12)
> list1 = eList('a')

That is a default parameter.  If eList() is called without an argument for
list0, it will use [] as the default value.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon@panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"

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


#99003

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-11-18 15:11 -0700
Message-ID<mailman.429.1447884751.16136.python-list@python.org>
In reply to#98999
On Wed, Nov 18, 2015 at 2:08 PM, fl <rxjwg98@gmail.com> wrote:
> Hi,
>
> I have tried the below function and find that it can remember the previous
> setting value to 'val'. I think the second parameter has something on this
> effect, but I don't know the name and function of '=[]' in this application.
>
> Could you explain a little to me?
> Thanks,
>
>
> def eList(val, list0=[]):
>     list0.append(val)
>     return list0
> list1 = eList(12)
> list1 = eList('a')

The list0 parameter has a default value, which is [], an initially
empty list. The default value is evaluated when the function is
defined, not when it is called, so the same list object is used each
time and changes to the list are consequently retained between calls.

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


#99004

FromGrant Edwards <invalid@invalid.invalid>
Date2015-11-18 22:33 +0000
Message-ID<n2iub7$vo$1@reader1.panix.com>
In reply to#99003
On 2015-11-18, Ian Kelly <ian.g.kelly@gmail.com> wrote:
> On Wed, Nov 18, 2015 at 2:08 PM, fl <rxjwg98@gmail.com> wrote:

>> def eList(val, list0=[]):

> The list0 parameter has a default value, which is [], an initially
> empty list. The default value is evaluated when the function is
> defined, not when it is called, so the same list object is used each
> time and changes to the list are consequently retained between calls.

One might consider this a way to have a local varible inside a
function that's "static" a-la C.  However, one probably oughtn't.

-- 
Grant Edwards               grant.b.edwards        Yow! Gibble, Gobble, we
                                  at               ACCEPT YOU ...
                              gmail.com            

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


#99006

Fromfl <rxjwg98@gmail.com>
Date2015-11-18 14:38 -0800
Message-ID<cea77860-b3d0-4ac0-9803-82ec270dfdb4@googlegroups.com>
In reply to#99003
On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote:
> On Wed, Nov 18, 2015 at 2:08 PM, fl <com> wrote:
> > Hi,
> >
> > I have tried the below function and find that it can remember the previous
> > setting value to 'val'. I think the second parameter has something on this
> > effect, but I don't know the name and function of '=[]' in this application.
> >
> > Could you explain a little to me?
> > Thanks,
> >
> >
> > def eList(val, list0=[]):
> >     list0.append(val)
> >     return list0
> > list1 = eList(12)
> > list1 = eList('a')
> 
> The list0 parameter has a default value, which is [], an initially
> empty list. The default value is evaluated when the function is
> defined, not when it is called, so the same list object is used each
> time and changes to the list are consequently retained between calls.

Thanks. The amazing thing to me is that the following two line codes:
list1 = eList(12) 
list2 = eList('a')

will have both list1 and list2 the same cascaded values:

list1
Out[2]: [12, 'a']

list2
Out[3]: [12, 'a']

I have known object concept in Python.
1. Why do they have the same list value?
 Function eList must be for this purpose?
2. If I want to have two separate lists, how to avoid the above result?
 Function eList is not for this purpose?

Thanks again.

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


#99008

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-11-18 15:47 -0700
Message-ID<mailman.430.1447886862.16136.python-list@python.org>
In reply to#99006
On Wed, Nov 18, 2015 at 3:38 PM, fl <rxjwg98@gmail.com> wrote:
> On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote:
>> On Wed, Nov 18, 2015 at 2:08 PM, fl <com> wrote:
>> > Hi,
>> >
>> > I have tried the below function and find that it can remember the previous
>> > setting value to 'val'. I think the second parameter has something on this
>> > effect, but I don't know the name and function of '=[]' in this application.
>> >
>> > Could you explain a little to me?
>> > Thanks,
>> >
>> >
>> > def eList(val, list0=[]):
>> >     list0.append(val)
>> >     return list0
>> > list1 = eList(12)
>> > list1 = eList('a')
>>
>> The list0 parameter has a default value, which is [], an initially
>> empty list. The default value is evaluated when the function is
>> defined, not when it is called, so the same list object is used each
>> time and changes to the list are consequently retained between calls.
>
> Thanks. The amazing thing to me is that the following two line codes:
> list1 = eList(12)
> list2 = eList('a')
>
> will have both list1 and list2 the same cascaded values:
>
> list1
> Out[2]: [12, 'a']
>
> list2
> Out[3]: [12, 'a']
>
> I have known object concept in Python.
> 1. Why do they have the same list value?
>  Function eList must be for this purpose?

Because eList returns list0, and as explained above list0 is the same
list in both calls. Therefore list1 and list2 are the same list.

> 2. If I want to have two separate lists, how to avoid the above result?
>  Function eList is not for this purpose?

The usual advice is to not use a mutable object as the default value.
If you want the default to be an empty list, it's usually better set
it to None and then make it an empty list if the value is None. For
example:

def eList(val, list0=None):
    if list0 is None:
        list0 = []
    list0.append(val)
    return list0

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


#99009

Fromfl <rxjwg98@gmail.com>
Date2015-11-18 14:48 -0800
Message-ID<49ad34bd-0943-4ac0-92e7-4636d2f9d447@googlegroups.com>
In reply to#99006
On Wednesday, November 18, 2015 at 5:38:45 PM UTC-5, fl wrote:
> On Wednesday, November 18, 2015 at 5:12:44 PM UTC-5, Ian wrote:
> > On Wed, Nov 18, 2015 at 2:08 PM, fl <com> wrote:
> > > Hi,
> > >
> > > I have tried the below function and find that it can remember the previous
> > > setting value to 'val'. I think the second parameter has something on this
> > > effect, but I don't know the name and function of '=[]' in this application.
> > >
> > > Could you explain a little to me?
> > > Thanks,
> > >
> > >
> > > def eList(val, list0=[]):
> > >     list0.append(val)
> > >     return list0
> > > list1 = eList(12)
> > > list1 = eList('a')
> > 
> > The list0 parameter has a default value, which is [], an initially
> > empty list. The default value is evaluated when the function is
> > defined, not when it is called, so the same list object is used each
> > time and changes to the list are consequently retained between calls.
> 
> Thanks. The amazing thing to me is that the following two line codes:
> list1 = eList(12) 
> list2 = eList('a')
> 
> will have both list1 and list2 the same cascaded values:
> 
> list1
> Out[2]: [12, 'a']
> 
> list2
> Out[3]: [12, 'a']
> 
> I have known object concept in Python.
> 1. Why do they have the same list value?
>  Function eList must be for this purpose?
> 2. If I want to have two separate lists, how to avoid the above result?
>  Function eList is not for this purpose?
> 
> Thanks again.

After several trials, I find that the cascade list is caused by the second
function parameter absent. It is interesting. Thanks.

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


#99010

FromBartC <bc@freeuk.com>
Date2015-11-18 23:14 +0000
Message-ID<n2j0k4$up4$1@dont-email.me>
In reply to#99003
On 18/11/2015 22:11, Ian Kelly wrote:
> On Wed, Nov 18, 2015 at 2:08 PM, fl <rxjwg98@gmail.com> wrote:
>> Hi,
>>
>> I have tried the below function and find that it can remember the previous
>> setting value to 'val'. I think the second parameter has something on this
>> effect, but I don't know the name and function of '=[]' in this application.
>>
>> Could you explain a little to me?
>> Thanks,
>>
>>
>> def eList(val, list0=[]):
>>      list0.append(val)
>>      return list0
>> list1 = eList(12)
>> list1 = eList('a')
>
> The list0 parameter has a default value, which is [], an initially
> empty list. The default value is evaluated when the function is
> defined, not when it is called, so the same list object is used each
> time and changes to the list are consequently retained between calls.

That is really bizarre behaviour.

So, looking at some source code, a default value for certain types is 
only certain to be that value for the very first call of that function?

 > The default value is evaluated when the function is
 > defined, not when it is called

Given the amount of pointless dynamic stuff that goes on in Python, I'm 
surprised they've overlooked this one!

It seems simple enough to me to check for a missing parameter, and to 
assign whatever default value was designated ([] in this case). (How 
does the default mechanism work now?)

-- 
Bartc

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


#99012

FromChris Angelico <rosuav@gmail.com>
Date2015-11-19 10:22 +1100
Message-ID<mailman.432.1447888928.16136.python-list@python.org>
In reply to#99010
On Thu, Nov 19, 2015 at 10:14 AM, BartC <bc@freeuk.com> wrote:
> On 18/11/2015 22:11, Ian Kelly wrote:
>>
>> On Wed, Nov 18, 2015 at 2:08 PM, fl <rxjwg98@gmail.com> wrote:
>>>
>>> Hi,
>>>
>>> I have tried the below function and find that it can remember the
>>> previous
>>> setting value to 'val'. I think the second parameter has something on
>>> this
>>> effect, but I don't know the name and function of '=[]' in this
>>> application.
>>>
>>> Could you explain a little to me?
>>> Thanks,
>>>
>>>
>>> def eList(val, list0=[]):
>>>      list0.append(val)
>>>      return list0
>>> list1 = eList(12)
>>> list1 = eList('a')
>>
>>
>> The list0 parameter has a default value, which is [], an initially
>> empty list. The default value is evaluated when the function is
>> defined, not when it is called, so the same list object is used each
>> time and changes to the list are consequently retained between calls.
>
>
> That is really bizarre behaviour.
>
> So, looking at some source code, a default value for certain types is only
> certain to be that value for the very first call of that function?

On the contrary, it is certain always to be that exact object.

>> The default value is evaluated when the function is
>> defined, not when it is called
>
> Given the amount of pointless dynamic stuff that goes on in Python, I'm
> surprised they've overlooked this one!
>
> It seems simple enough to me to check for a missing parameter, and to assign
> whatever default value was designated ([] in this case). (How does the
> default mechanism work now?)

It's exactly the way Ian described it. Functions are defined, not
declared - it's an executable statement. When the 'def' statement is
reached, the expressions in the argument defaults get evaluated, and
the results get saved into the function's attributes:

>>> def demo(factory):
...     def func(x=factory()):
...         x.append("Hello!")
...         return x
...     return func
...
>>> def make_list():
...     print("I'm making a list!")
...     return []
...
>>> f1 = demo(make_list)
I'm making a list!
>>> f2 = demo(make_list)
I'm making a list!
>>> f3 = demo(make_list)
I'm making a list!
>>> f1()
['Hello!']
>>> f1()
['Hello!', 'Hello!']
>>> f1()
['Hello!', 'Hello!', 'Hello!']
>>> f2()
['Hello!']
>>> f2()
['Hello!', 'Hello!']
>>> f3()
['Hello!']
>>> f1.__defaults__
(['Hello!', 'Hello!', 'Hello!'],)
>>> id(f1())
140470001247688
>>> id(f1())
140470001247688
>>> id(f1())
140470001247688
>>> id(f1())
140470001247688
>>> id(f1())
140470001247688
>>> id(f1.__defaults__[0])
140470001247688

If you want the expression (eg the empty list display) to be evaluated
every time the body of the function is executed, you put it into the
body of the function. There is no magic here.

ChrisA

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


#99024

FromBartC <bc@freeuk.com>
Date2015-11-19 01:41 +0000
Message-ID<n2j98r$o9c$1@dont-email.me>
In reply to#99012
On 18/11/2015 23:22, Chris Angelico wrote:
> On Thu, Nov 19, 2015 at 10:14 AM, BartC <bc@freeuk.com> wrote:
>> On 18/11/2015 22:11, Ian Kelly wrote:
>>>
>>> On Wed, Nov 18, 2015 at 2:08 PM, fl <rxjwg98@gmail.com> wrote:
>>>>
>>>> Hi,
>>>>
>>>> I have tried the below function and find that it can remember the
>>>> previous
>>>> setting value to 'val'. I think the second parameter has something on
>>>> this
>>>> effect, but I don't know the name and function of '=[]' in this
>>>> application.
>>>>
>>>> Could you explain a little to me?
>>>> Thanks,
>>>>
>>>>
>>>> def eList(val, list0=[]):
>>>>       list0.append(val)
>>>>       return list0
>>>> list1 = eList(12)
>>>> list1 = eList('a')
>>>
>>>
>>> The list0 parameter has a default value, which is [], an initially
>>> empty list. The default value is evaluated when the function is
>>> defined, not when it is called, so the same list object is used each
>>> time and changes to the list are consequently retained between calls.
>>
>>
>> That is really bizarre behaviour.
>>
>> So, looking at some source code, a default value for certain types is only
>> certain to be that value for the very first call of that function?
>
> On the contrary, it is certain always to be that exact object.

But, not the same value that appears as the default?

  >>> The default value is evaluated when the function is
>>> defined, not when it is called
>>
>> Given the amount of pointless dynamic stuff that goes on in Python, I'm
>> surprised they've overlooked this one!
>>
>> It seems simple enough to me to check for a missing parameter, and to assign
>> whatever default value was designated ([] in this case). (How does the
>> default mechanism work now?)
>
> It's exactly the way Ian described it. Functions are defined, not
> declared - it's an executable statement. When the 'def' statement is
> reached, the expressions in the argument defaults get evaluated, and
> the results get saved into the function's attributes:
....

Sorry, I didn't understand any of that. Let's try a simpler example like 
the OP's. There's this innocuous looking function that you are 
interested in calling:

  def fn(a=[]):
  #   print ("Function fn called with",a)
  |   a.append(10)
  |   return a

It appends a value to its argument and returns the result.

It looks like at first like, if called with no argument, it will return 
[10].

But what it actually returns depends on the entire call history since 
the program started executing, something you probably have no knowledge 
of and no control over. So if fn has previously been called a million 
times with no argument, then after this call:

  x=fn()

x contains a list of a million tens, not one. I'd say most people would 
be rather surprised by that.

I suspect those same people (unless they are experts in the murky 
corners of the language) would expect:

   x=fn()

when fn specifies a default argument of [], to be the same as writing:

   x=fn([])

and not be dependent on fn's entire call history.

Your solution of using:

   def fn(a=None):

is not really satisfactory. Partly because it now utilities two 
mechanisms for the default: first to get None, then some extra code to 
get []. But also it's no longer obvious how the function works and what 
the default is. At least, you can't tell from a glance at the start of 
the function that [] is the default.

-- 
Bartc

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


#99025

FromChris Angelico <rosuav@gmail.com>
Date2015-11-19 12:59 +1100
Message-ID<mailman.440.1447898362.16136.python-list@python.org>
In reply to#99024
On Thu, Nov 19, 2015 at 12:41 PM, BartC <bc@freeuk.com> wrote:
> On 18/11/2015 23:22, Chris Angelico wrote:
>> On the contrary, it is certain always to be that exact object.
>
> But, not the same value that appears as the default?

Nope. Mutable objects are never guaranteed to retain the same values.
That's kinda the point.

> Sorry, I didn't understand any of that. Let's try a simpler example like the
> OP's. There's this innocuous looking function that you are interested in
> calling:
>
>  def fn(a=[]):
>  #   print ("Function fn called with",a)
>  |   a.append(10)
>  |   return a
>
> It appends a value to its argument and returns the result.
>
> It looks like at first like, if called with no argument, it will return
> [10].

If you want to think of function defaults as being values, then yes.
But they're not. They're objects.

> But what it actually returns depends on the entire call history since the
> program started executing, something you probably have no knowledge of and
> no control over. So if fn has previously been called a million times with no
> argument, then after this call:
>
>  x=fn()
>
> x contains a list of a million tens, not one. I'd say most people would be
> rather surprised by that.

So if you don't want them to be surprised by that, don't use mutable
default arguments and expect them to have specific values.

> I suspect those same people (unless they are experts in the murky corners of
> the language) would expect:
>
>   x=fn()
>
> when fn specifies a default argument of [], to be the same as writing:
>
>   x=fn([])
>
> and not be dependent on fn's entire call history.

Tell me, do you expect these to do the same thing?

x = []
fn(x)
fn(x)
fn(x)

# or

fn([])
fn([])
fn([])

The distinction is exactly the same. If you can understand that the
first one constructs a single object and uses it three times, then you
should be able to understand that the function default is also
constructed once and used every time.

> Your solution of using:
>
>   def fn(a=None):
>
> is not really satisfactory. Partly because it now utilities two mechanisms
> for the default: first to get None, then some extra code to get []. But also
> it's no longer obvious how the function works and what the default is. At
> least, you can't tell from a glance at the start of the function that [] is
> the default.

This I do agree with. It's a bit clunky. It would be nice to be able to say:

def fn(a=`[]`):
    """If a is not passed, it will be a new empty list"""

and have it function the same as:

def fn(*args):
    a = args[0] if args else []

but currently there's no mechanism for it. (The example spelling I
gave is almost certainly not going to be used, due to the Tim Peters'
Monitor Grit argument, but something could probably be found.) It's a
sufficiently common situation that it would merit its own syntax. Want
to write up a PEP? All you need is a syntax that people can get
behind.

ChrisA

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


#99047

FromBartC <bc@freeuk.com>
Date2015-11-19 11:41 +0000
Message-ID<n2kcdn$lq0$1@dont-email.me>
In reply to#99025
On 19/11/2015 01:59, Chris Angelico wrote:
> On Thu, Nov 19, 2015 at 12:41 PM, BartC <bc@freeuk.com> wrote:
>> On 18/11/2015 23:22, Chris Angelico wrote:
>>> On the contrary, it is certain always to be that exact object.
>>
>> But, not the same value that appears as the default?
>
> Nope. Mutable objects are never guaranteed to retain the same values.
> That's kinda the point.

But, presumably you would expect:

  a = []

to always assign an empty list to a? You don't expect this:

  a = []
  a.append(10)
  b = []

that b now has the same value of a, namely [10]. Fortunately this isn't 
the case.

>> Sorry, I didn't understand any of that.

> If you want to think of function defaults as being values, then yes.
> But they're not. They're objects.

That's not much help to someone who *does* want the default to supply 
the same missing value that they don't want to bother remembering and/or 
writing in the call.

Surely the language is trying to help people not hinder. How many times 
after all is this behaviour actually wanted? It's the equivalent of:

fndefault=[]

def fn(a=fndefault):
     a.append(10)
     return a

where it is known that a and fndefault share the same mutable data. 
(Although I bet some people are still surprised by that!)

>> I suspect those same people (unless they are experts in the murky corners of
>> the language) would expect:
....
>> and not be dependent on fn's entire call history.
>
> Tell me, do you expect these to do the same thing?
>
> x = []
> fn(x)
> fn(x)
> fn(x)
>
> # or
>
> fn([])
> fn([])
> fn([])

No I don't. But I expect the version with the default argument to be 
exactly the same as the last lot of calls, namely for:

fn()
fn()
fn()

to be equivalent to:

temp=[]
fn(temp)
temp=[]
fn(temp)
temp=[]
fn(temp)

> The distinction is exactly the same. If you can understand that the
> first one constructs a single object and uses it three times, then you
> should be able to understand that the function default is also
> constructed once and used every time.

As I said, it's bizarre. It means that for certain types, Python doesn't 
have a default that works per call, but only a default that works once 
per program.

-- 
Bartc

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


#99050

FromChris Angelico <rosuav@gmail.com>
Date2015-11-19 22:58 +1100
Message-ID<mailman.456.1447934323.16136.python-list@python.org>
In reply to#99047
On Thu, Nov 19, 2015 at 10:41 PM, BartC <bc@freeuk.com> wrote:
> As I said, it's bizarre. It means that for certain types, Python doesn't
> have a default that works per call, but only a default that works once per
> program.

No, it's not "for certain types". Regardless of the type, the
expression that defines the default is evaluated at *function
definition*, not at each *function call*. (That's not the same as
"once per program", although for 99% of situations, it'll be
indistinguishable.)

ChrisA

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


#99055

FromSteven D'Aprano <steve@pearwood.info>
Date2015-11-19 23:45 +1100
Message-ID<564dc478$0$1609$c3e8da3$5496439d@news.astraweb.com>
In reply to#99047
On Thu, 19 Nov 2015 10:41 pm, BartC wrote:


> I expect the version with the default argument to be
> exactly the same as the last lot of calls, namely for:
> 
> fn()
> fn()
> fn()
> 
> to be equivalent to:
> 
> temp=[]
> fn(temp)
> temp=[]
> fn(temp)
> temp=[]
> fn(temp)

Why on earth would you expect that?

I don't mean that it isn't sometimes useful. Of course it is sometimes
useful, there's no doubt about that. But why would you expect the language
to default to the *slow*, *expensive*, *complicated* behaviour instead of
the *fast*, *cheap*, *simple* behaviour?

You already have one way to set the argument to a fresh list every time you
call the function: put the code you want executed inside the body of the
function. There's no need for a *second* way to get the same result.

But if you want the default value to be evaluated exactly once, and once
only, there is no real alternative to early binding. You could use a global
variable, of course, but that is no solution -- that's a problem waiting to
happen.

To get late binding, the interpreter needs to record the default expression
*and its scope* in some sort of executable code. The traditional name for
that is stolen from Algol, "thunk". And you need to decide whether it will
behave like a closure or not.

It needs to work sensibly with code like this:


i = j = k = -1
def demo():
    array = []
    for i in range(5):
        def factory():
            j = i
            def f(x=i + i**2, y=3*j+1, z=k**2 - k):
                return ((x, y, z), (i, j, k))
            return f
        array.append(factory())
    return array

func = demo()[1]
i = j = k = 9999
print(func())


>> The distinction is exactly the same. If you can understand that the
>> first one constructs a single object and uses it three times, then you
>> should be able to understand that the function default is also
>> constructed once and used every time.
> 
> As I said, it's bizarre. It means that for certain types, Python doesn't
> have a default that works per call, but only a default that works once
> per program.

Nonsense. The semantics of default values is *completely* independent of the
type. Python ALWAYS uses early binding, regardless of the type. Whether the
default is an int, None, a list, a dict, a float, or some other instance,
the behaviour is the same: the default value is the specific instance which
the default expression evaluates to when the function is created.


-- 
Steven

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


#99063

FromIan Kelly <ian.g.kelly@gmail.com>
Date2015-11-19 08:42 -0700
Message-ID<mailman.465.1447947763.16136.python-list@python.org>
In reply to#99055
On Thu, Nov 19, 2015 at 5:45 AM, Steven D'Aprano <steve@pearwood.info> wrote:
> But if you want the default value to be evaluated exactly once, and once
> only, there is no real alternative to early binding. You could use a global
> variable, of course, but that is no solution -- that's a problem waiting to
> happen.

It doesn't have to be a global. In a Python with late binding
defaults, this would work to get early binding:

def f(x=f.default_x):
    ...

f.default_x = something()

Of course, assignment to function attributes is a relatively modern
thing that is only permitted since Python 2.1, whereas function
defaults have been around since at least 1.4, so this wouldn't have
been an option when the semantics were being determined.

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


#99229

FromSteven D'Aprano <steve@pearwood.info>
Date2015-11-22 14:58 +1100
Message-ID<56513d58$0$1619$c3e8da3$5496439d@news.astraweb.com>
In reply to#99063
On Fri, 20 Nov 2015 02:42 am, Ian Kelly wrote:

> On Thu, Nov 19, 2015 at 5:45 AM, Steven D'Aprano <steve@pearwood.info>
> wrote:
>> But if you want the default value to be evaluated exactly once, and once
>> only, there is no real alternative to early binding. You could use a
>> global variable, of course, but that is no solution -- that's a problem
>> waiting to happen.
> 
> It doesn't have to be a global. In a Python with late binding
> defaults, this would work to get early binding:
> 
> def f(x=f.default_x):
>     ...
> 
> f.default_x = something()


Ah, of course it can. Good catch.

As an illustration of how your expectations can colour your thinking, I
actually considered that, but rejected it as a possibility because
f.default_x couldn't be created until the function came into existence, and
the function couldn't come into existence until after f.default_x was
evaluated.

In other words, I was making the complementary error to BartC's: I was still
thinking in terms of early binding, when describing late binding.

In fact, what Python actually does is rather similar, except that instead
of "f.default_x" it uses f.__defaults__[0]. Roughly speaking, the function
declaration

def f(x=something()): ...

using early-binding is somewhat analogous to this using late-binding:

def f(x=f.__defaults__[0]): ...

f.__defaults__ = (something(), )


> Of course, assignment to function attributes is a relatively modern
> thing that is only permitted since Python 2.1, whereas function
> defaults have been around since at least 1.4, so this wouldn't have
> been an option when the semantics were being determined.

I suspect that had Guido decided on late binding as the preferred semantics,
he would have allowed function attributes much earlier.



-- 
Steven

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


#99323

FromAntoon Pardon <antoon.pardon@rece.vub.ac.be>
Date2015-11-24 13:38 +0100
Message-ID<mailman.109.1448368689.2291.python-list@python.org>
In reply to#99055
Op 19-11-15 om 13:45 schreef Steven D'Aprano:
> On Thu, 19 Nov 2015 10:41 pm, BartC wrote:
> 
> 
>> I expect the version with the default argument to be
>> exactly the same as the last lot of calls, namely for:
>>
>> fn()
>> fn()
>> fn()
>>
>> to be equivalent to:
>>
>> temp=[]
>> fn(temp)
>> temp=[]
>> fn(temp)
>> temp=[]
>> fn(temp)
> 
> Why on earth would you expect that?
> 
> I don't mean that it isn't sometimes useful. Of course it is sometimes
> useful, there's no doubt about that. But why would you expect the language
> to default to the *slow*, *expensive*, *complicated* behaviour instead of
> the *fast*, *cheap*, *simple* behaviour?

I would say because it is better understandable. The way default value
behave now, is just a little less surprising as when the following segment
of code would print: [1]

a = []
a.append(1)
b = []
print b

Let us not forget that the tutorial talks about Default Argument *Values*.
And also the language reference talks about precomputed *values*. What
we really get is a precomputed object.

> You already have one way to set the argument to a fresh list every time you
> call the function: put the code you want executed inside the body of the
> function. There's no need for a *second* way to get the same result.

Which is beside the point. The point is understandability.

> But if you want the default value to be evaluated exactly once, and once
> only, there is no real alternative to early binding. You could use a global
> variable, of course, but that is no solution -- that's a problem waiting to
> happen.

No more than the situation we have now. The situation we have now is a problem
waiting to happen too. Which is confirmed again and again. You are stacking
the deck by calling a possible alternative "a problem waiting to happen" while
ignoring the problems that happen with the current situation.

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


#99371

FromSteven D'Aprano <steve@pearwood.info>
Date2015-11-25 04:29 +1100
Message-ID<56549e92$0$1604$c3e8da3$5496439d@news.astraweb.com>
In reply to#99323
On Tue, 24 Nov 2015 11:38 pm, Antoon Pardon wrote:

> Op 19-11-15 om 13:45 schreef Steven D'Aprano:
[...]
>> I don't mean that it isn't sometimes useful. Of course it is sometimes
>> useful, there's no doubt about that. But why would you expect the
>> language to default to the *slow*, *expensive*, *complicated* behaviour
>> instead of the *fast*, *cheap*, *simple* behaviour?
> 
> I would say because it is better understandable. 

I disagree that it (late-binding) is more understandable. 

Late-binding (or, "late evaluation" for those who prefer that term) is no
easier to understand than early binding. Earlier, I publicly screwed up
reasoning about late binding.

And so did BartC, whose personal language has precisely the late binding
semantics he wants, exactly as he designed it, and yet he was surprised by
its behaviour leading him to (wrongly) conclude that his language was more
dynamic than Python:

Quote:

    "(Python returns 42; so that means my languages are more dynamic than 
    Python? That's hard to believe!)"

See this thread, post from BartC dated Fri, 20 Nov 2015 08:21:24 am.


> The way default value 
> behave now, is just a little less surprising as when the following segment
> of code would print: [1]
> 
> a = []
> a.append(1)
> b = []
> print b

No, it really isn't anything like that at all. If you (generic you, not
specifically you personally) think that it is similar, you've misunderstood
what is going on.

If we want an analogy, this is a good one:

alist = []
for i in range(20):
    alist.append(i)
    print alist


Are you surprised that alist keeps growing? Contrast this to:


for i in range(20):
    alist = []
    alist.append(i)
    print alist


Are you surprised that alist keeps getting re-set to the empty list?


Change the for-loop to a function declaration. If the binding of the list []
happens inside the indented block, it will happen every time the function
is called (just as it happens each time through the loop in the second
example above). If the binding happens outside of the body, it happens
once, not every time.

Folk like BartC want the function default to be re-evaluated every time the
function is called. I'm not blind to the usefulness of it: I write lots of
functions with late-binding semantics too. I just write them like this:

def func(a=None):
    if a is None:
        a = something()


Perhaps as more people start using function annotations, it will become more
obvious that function declarations aren't re-evaluated every single time
you call the function:

def func(a:some_expression=another_expression): ...

*Both* expressions, the annotation and the default, are evaluated once and
once only.


> Let us not forget that the tutorial talks about Default Argument *Values*.
> And also the language reference talks about precomputed *values*. What
> we really get is a precomputed object.

There is a distinction between value and object, but without seeing the
exact wording and context of the tutorial and language reference, I cannot
tell whether they are misleading or not. There's nothing wrong with talking
about default values. You just have to remember that some values can
change.


>> You already have one way to set the argument to a fresh list every time
>> you call the function: put the code you want executed inside the body of
>> the function. There's no need for a *second* way to get the same result.
> 
> Which is beside the point. The point is understandability.

Okay. Suppose for the sake of the argument I agree with you
that "understandability" is the most important factor here.

Then early binding is still the clear winner, because it has simple, easy to
understand semantics:

- the "def" line is executed once, and once only, including all parameter
defaults and annotations;

- the *body* of the function is executed when the function is called, not
the "def" function declaration.

Since the function defaults are part of the declaration, not the body, it is
far more understandable that it is executed once only.



>> But if you want the default value to be evaluated exactly once, and once
>> only, there is no real alternative to early binding. You could use a
>> global variable, of course, but that is no solution -- that's a problem
>> waiting to happen.
> 
> No more than the situation we have now. The situation we have now is a
> problem waiting to happen too. Which is confirmed again and again. You are
> stacking the deck by calling a possible alternative "a problem waiting to
> happen" while ignoring the problems that happen with the current
> situation.

Pardon me, I certainly am not ignoring anything of the sort. I do
acknowledge that the behaviour of mutable defaults can be surprising. I
even admitted that it surprised me. It's often not the behaviour that you
want, so you have to do something slightly different.

The bottom line is that there are good reasons for the way Python works with
function defaults, but they aren't good for everything. Neither is the
alternative. Whichever design Python used, it would inconvenience people at
some time or another.



-- 
Steven

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


#99026

FromBen Finney <ben+python@benfinney.id.au>
Date2015-11-19 13:08 +1100
Message-ID<mailman.441.1447898935.16136.python-list@python.org>
In reply to#99024
Chris Angelico <rosuav@gmail.com> writes:

> On Thu, Nov 19, 2015 at 12:41 PM, BartC <bc@freeuk.com> wrote:
> > On 18/11/2015 23:22, Chris Angelico wrote:
> >> On the contrary, it is certain always to be that exact object.
> >
> > But, not the same value that appears as the default?

It depends what you mean by “the same value”.

> Nope. Mutable objects are never guaranteed to retain the same values.
> That's kinda the point.

Well, they are the *same value*, if by “value” you mean “a particular
object”.

On the other hand, the value can *change* over time, while remaining the
same object. So it will not be equal to its initial state, even though
it is the same object.

-- 
 \     “[F]reedom of speech does not entail freedom to have your ideas |
  `\    accepted by governments and incorporated into law and policy.” |
_o__)                                   —Russell Blackford, 2010-03-06 |
Ben Finney

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


#99027

FromChris Angelico <rosuav@gmail.com>
Date2015-11-19 13:15 +1100
Message-ID<mailman.442.1447899337.16136.python-list@python.org>
In reply to#99024
On Thu, Nov 19, 2015 at 1:08 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
>> Nope. Mutable objects are never guaranteed to retain the same values.
>> That's kinda the point.
>
> Well, they are the *same value*, if by “value” you mean “a particular
> object”.
>
> On the other hand, the value can *change* over time, while remaining the
> same object. So it will not be equal to its initial state, even though
> it is the same object.

I would normally interpret "value" as "the quality compared with the
== operator". As such, mutables can change in value while retaining
their identities:

>>> x, y = [], []
>>> x == y
True
>>> x.append(1)
>>> x == y
False
>>> y.append(1)
>>> x == y
True

So a mutable default argument will always retain its identity (barring
shenanigans), but may not retain its value.

ChrisA

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


Page 1 of 10  [1] 2 3 … 10  Next page →

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


csiph-web