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


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

Can global variable be passed into Python function?

Started bySam <lightaiyee@gmail.com>
First post2014-02-20 22:37 -0800
Last post2014-03-01 15:22 +1100
Articles 20 on this page of 219 — 28 participants

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


Contents

  Can global variable be passed into Python function? Sam <lightaiyee@gmail.com> - 2014-02-20 22:37 -0800
    Re: Can global variable be passed into Python function? dieter <dieter@handshake.de> - 2014-02-21 08:23 +0100
      Re: Can global variable be passed into Python function? Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-02-21 10:55 +0200
        Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-21 12:10 +0200
    Re: Can global variable be passed into Python function? Peter Otten <__peter__@web.de> - 2014-02-21 08:34 +0100
    Re: Can global variable be passed into Python function? Gary Herron <gary.herron@islandtraining.com> - 2014-02-21 00:41 -0800
    Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-21 08:55 +0000
    Re: Can global variable be passed into Python function? Ned Batchelder <ned@nedbatchelder.com> - 2014-02-21 07:13 -0500
      Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-21 14:52 +0200
      Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-22 03:28 +0000
        Re: Can global variable be passed into Python function? Ned Batchelder <ned@nedbatchelder.com> - 2014-02-21 22:45 -0500
          Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-22 06:29 +0000
    Re: Can global variable be passed into Python function? Travis Griggs <travisgriggs@gmail.com> - 2014-02-21 09:59 -0800
    Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-22 05:16 +1100
      Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-21 21:20 +0200
        Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-22 17:36 +1100
          Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-22 07:18 +0000
            Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-22 18:29 +1100
              Re: Can global variable be passed into Python function? wxjmfauth@gmail.com - 2014-02-22 00:02 -0800
                Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-22 19:10 +1100
                  Re: Can global variable be passed into Python function? wxjmfauth@gmail.com - 2014-02-22 00:26 -0800
                  Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-22 08:28 +0000
              Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-22 08:35 +0000
                Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-22 19:45 +1100
                Re: Can global variable be passed into Python function? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-24 21:07 +1300
                  Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-24 15:57 +0000
                    Re: Can global variable be passed into Python function? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-24 21:12 -0500
                    Re: Can global variable be passed into Python function? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-02-26 23:59 +1300
                      Re: Can global variable be passed into Python function? MRAB <python@mrabarnett.plus.com> - 2014-02-26 18:59 +0000
        Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-22 06:57 +0000
          Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-22 09:28 +0200
            Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-22 08:45 +0000
              Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-22 19:54 +1100
    Python and variables (was: Can global variable be passed into Python function?) Ben Finney <ben+python@benfinney.id.au> - 2014-02-22 11:13 +1100
    Re: Can global variable be passed into Python function? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-21 21:47 -0500
    Re: Can global variable be passed into Python function? Ned Batchelder <ned@nedbatchelder.com> - 2014-02-21 22:14 -0500
    Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-22 14:15 +0000
      Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-22 16:44 +0200
      Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-23 01:39 +0000
        Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-23 12:50 +1100
          Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-23 06:20 +0000
            Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-23 18:23 +1100
        Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-23 11:52 +0200
          Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-23 10:30 +0000
          Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-23 21:32 +1100
            Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-23 13:01 +0200
              Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-23 22:12 +1100
                Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-23 17:24 +0200
                  Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-24 02:41 +1100
                    Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-23 23:04 +0200
                      Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-23 21:18 +0000
              Re: Can global variable be passed into Python function? Terry Reedy <tjreedy@udel.edu> - 2014-02-23 12:06 -0500
                Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-23 23:10 +0200
                  Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-24 00:37 +0000
                    Re: Can global variable be passed into Python function? wxjmfauth@gmail.com - 2014-02-24 01:35 -0800
              Re: Can global variable be passed into Python function? j.e.haque@gmail.com - 2014-02-24 10:05 -0800
                Re: [OT] Can global variable be passed into Python function? Michael Torrie <torriem@gmail.com> - 2014-02-24 11:19 -0700
                  Re: [OT] Can global variable be passed into Python function? Grant Edwards <invalid@invalid.invalid> - 2014-02-24 19:42 +0000
                    Re: [OT] Can global variable be passed into Python function? Dave Angel <davea@davea.name> - 2014-03-01 23:02 -0500
                      Re: [OT] Can global variable be passed into Python function? Grant Edwards <invalid@invalid.invalid> - 2014-03-02 16:45 +0000
                        Re: [OT] Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-02 16:55 +0000
                        Re: [OT] Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-03 06:24 +1100
                          Re: [OT] Can global variable be passed into Python function? Grant Edwards <invalid@invalid.invalid> - 2014-03-03 14:18 +0000
                            Re: [OT] Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-04 01:25 +1100
                    Re: [OT] Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-02 15:17 +1100
                    Re: [OT] Can global variable be passed into Python function? Dave Angel <davea@davea.name> - 2014-03-02 08:22 -0500
                    Re: [OT] Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-03 00:57 +1100
                    Re: [OT] Can global variable be passed into Python function? Dave Angel <davea@davea.name> - 2014-03-02 14:17 -0500
                    Re: [OT] Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-03 06:32 +1100
                    Re: [OT] Can global variable be passed into Python function? Dave Angel <davea@davea.name> - 2014-03-02 17:58 -0500
                Re: Can global variable be passed into Python function? random832@fastmail.us - 2014-02-24 13:20 -0500
                Re: [OT] Can global variable be passed into Python function? random832@fastmail.us - 2014-02-24 13:21 -0500
                Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-25 05:22 +1100
                Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-25 05:25 +1100
                Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-24 20:00 +0000
    Re: Can global variable be passed into Python function? Dave Angel <davea@davea.name> - 2014-02-22 10:02 -0500
    Re: Can global variable be passed into Python function? Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-22 13:03 -0500
      Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-23 00:39 +0000
      Re: Can global variable be passed into Python function? Roy Smith <roy@panix.com> - 2014-02-22 19:57 -0500
    Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-27 05:24 -0800
      Re: Can global variable be passed into Python function? Ned Batchelder <ned@nedbatchelder.com> - 2014-02-27 12:54 -0500
        Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-27 15:29 -0800
          Re: Can global variable be passed into Python function? Steven D'Aprano <steve@pearwood.info> - 2014-02-28 02:07 +0000
            Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-27 18:29 -0800
              Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-28 15:43 +1100
                Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-27 21:39 -0800
                  Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-28 16:53 +1100
                Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 09:43 +0200
                  Re: Can global variable be passed into Python function? Steven D'Aprano <steve@pearwood.info> - 2014-02-28 08:23 +0000
                    Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-02-28 19:46 +1100
                      Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 12:02 +0200
                        Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-28 21:55 +1100
                          Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 13:30 +0200
                            Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-28 22:51 +1100
                              Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 14:25 +0200
                                Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-01 00:22 +0000
                        Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-28 22:08 +1100
                          Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 13:38 +0200
                            Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-28 23:22 +1100
                            Re: Can global variable be passed into Python function? Neil Cerutti <neilc@norwich.edu> - 2014-02-28 13:47 +0000
                              Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 16:26 +0200
                                Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-01 01:37 +1100
                                  Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 17:29 +0200
                                    Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-01 02:46 +1100
                                    Re: Can global variable be passed into Python function? Grant Edwards <invalid@invalid.invalid> - 2014-02-28 16:09 +0000
                                      Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-02 10:00 +0200
                                Re: Can global variable be passed into Python function? Roy Smith <roy@panix.com> - 2014-02-28 09:43 -0500
                                  Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-02 10:00 +0200
                                    Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-02 17:26 +0200
                                      Re: Can global variable be passed into Python function? Roy Smith <roy@panix.com> - 2014-03-02 10:34 -0500
                                        Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-02 17:52 +0200
                                          Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-03 03:23 +1100
                                          Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-02 16:53 +0000
                            Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-28 15:06 +0000
                        Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-28 15:50 +0000
                          Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 10:04 -0800
                            Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 20:53 +0200
                              Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-01 05:59 +1100
                                Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 21:20 +0200
                                  Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 12:22 -0800
                                    Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-02-28 23:03 +0200
                                      Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-28 21:23 +0000
                                        Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 01:06 +0200
                                          Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-03-01 11:02 +1100
                                            Re: Can global variable be passed into Python function? Roy Smith <roy@panix.com> - 2014-02-28 19:48 -0500
                                          Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-01 13:00 +1100
                                            Re: Can global variable be passed into Python function? Roy Smith <roy@panix.com> - 2014-02-28 22:15 -0500
                                          Re: Can global variable be passed into Python function? albert@spenarnc.xs4all.nl (Albert van der Horst) - 2014-03-10 14:12 +0000
                                            Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-10 16:29 +0200
                                        Re: Can global variable be passed into Python function? Grant Edwards <invalid@invalid.invalid> - 2014-02-28 22:00 +0000
                                          Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-03-02 09:36 +1100
                                            Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 14:50 -0800
                                      Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 15:36 -0800
                                        Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 02:32 +0200
                                        Re: Can global variable be passed into Python function? Ned Batchelder <ned@nedbatchelder.com> - 2014-02-28 19:40 -0500
                                          Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 17:08 -0800
                                            Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-01 13:01 +1100
                                              Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 21:30 -0800
                                                Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-01 17:24 +1100
                                                  Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 13:40 -0800
                                                    Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-01 22:01 +0000
                                                      Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 14:07 -0800
                                                        Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-01 23:21 +0000
                                                          Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-03-01 16:23 -0800
                                                            Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-02 11:28 +1100
                                                            Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-02 00:36 +0000
                                                            Re: Can global variable be passed into Python function? Ned Deily <nad@acm.org> - 2014-03-01 16:55 -0800
                                                            Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-02 01:15 +0000
                                                    Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-02 09:11 +1100
                                            Re: Can global variable be passed into Python function? Ned Batchelder <ned@nedbatchelder.com> - 2014-02-28 21:15 -0500
                                              Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 20:36 -0800
                                        Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-01 01:07 +0000
                                        Re: Can global variable be passed into Python function? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-03-01 16:10 +1300
                                        Re: Can global variable be passed into Python function? Roy Smith <roy@panix.com> - 2014-02-28 19:02 -0500
                                  Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-28 23:33 +0000
                                  Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-01 12:50 +1100
                              Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-02-28 23:04 +0000
                                Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 02:03 +0200
                                  Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-01 00:44 +0000
                                    Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 03:06 +0200
                                      Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-01 01:59 +0000
                                        Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-01 13:03 +1100
                                          Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-01 03:29 +0000
                                        Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 12:39 +0200
                                  Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-01 01:10 +0000
                                    Re: Can global variable be passed into Python function? "Mark H. Harris" <harrismh777@gmail.com> - 2014-02-28 17:29 -0800
                        Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-03-01 10:17 +1100
                          Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 02:11 +0200
                            Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-03-01 11:50 +1100
                              Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 03:10 +0200
                                Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-01 01:19 +0000
                                Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-03-01 12:41 +1100
                                  Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 12:31 +0200
                                    Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-03-01 21:48 +1100
                                      Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 13:28 +0200
                                        Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-01 22:59 +1100
                                          Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-01 17:07 +0000
                                            Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-02 04:27 +1100
                                            Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 20:25 +0200
                                              Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-03-02 09:30 +1100
                                              Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-01 23:13 +0000
                                        Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-03-02 00:03 +1100
                                          Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 19:23 +0200
                                            Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-02 04:30 +1100
                                            Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-03-02 09:34 +1100
                                              Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-02 10:03 +0200
                                                Re: Can global variable be passed into Python function? Ben Finney <ben+python@benfinney.id.au> - 2014-03-02 21:59 +1100
                                                Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-02 13:00 +0000
                                        Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-01 15:15 +0000
                                        Re: Can global variable be passed into Python function? Michael Torrie <torriem@gmail.com> - 2014-03-01 10:05 -0700
                                          Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-01 19:29 +0200
                                            Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-02 04:36 +1100
                                            Re: Can global variable be passed into Python function? Michael Torrie <torriem@gmail.com> - 2014-03-01 11:06 -0700
                                            Re: Can global variable be passed into Python function? Roy Smith <roy@panix.com> - 2014-03-01 13:30 -0500
                                            Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-02 08:35 +0000
                                              Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-02 11:35 +0200
                                                Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-02 11:40 +0200
                                                Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-02 21:07 +1100
                                                  Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-02 12:37 +0200
                                                Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-02 10:44 +0000
                                                  Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-02 13:33 +0200
                                                    Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-03 01:50 +0000
                                                Re: Can global variable be passed into Python function? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-02 13:04 +0000
                                                Re: Can global variable be passed into Python function? Michael Torrie <torriem@gmail.com> - 2014-03-02 11:48 -0700
                                                  Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-02 23:03 +0200
                                                    Re: Can global variable be passed into Python function? Roy Smith <roy@panix.com> - 2014-03-02 16:16 -0500
                                                    Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-03-03 08:28 +1100
                                                    Re: Can global variable be passed into Python function? Michael Torrie <torriem@gmail.com> - 2014-03-02 14:44 -0700
                                                      Re: Can global variable be passed into Python function? Marko Rauhamaa <marko@pacujo.net> - 2014-03-03 00:46 +0200
                                    Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-01 17:18 +0000
                            Re: Can global variable be passed into Python function? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-03-01 00:58 +0000
                    Re: Can global variable be passed into Python function? Michael Torrie <torriem@gmail.com> - 2014-02-28 07:49 -0700
                  Re: Can global variable be passed into Python function? Chris Angelico <rosuav@gmail.com> - 2014-02-28 20:00 +1100
                  Re: Can global variable be passed into Python function? Grant Edwards <invalid@invalid.invalid> - 2014-02-28 14:20 +0000
          References, and avoiding use of “variable” (was: Can global variable be passed into Python function?) Ben Finney <ben+python@benfinney.id.au> - 2014-02-28 13:46 +1100
          Re: References, and avoiding use of ???variable??? (was: Can global variable be passed into Python function?) Neil Cerutti <neilc@norwich.edu> - 2014-02-28 14:30 +0000
          Re: References, and avoiding use of ???variable??? Ben Finney <ben+python@benfinney.id.au> - 2014-03-01 10:33 +1100
            Re: References, and avoiding use of ???variable??? Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-03-01 16:08 +1300
              Re: References, and avoiding use of ???variable??? Ben Finney <ben+python@benfinney.id.au> - 2014-03-01 15:22 +1100

Page 9 of 11 — ← Prev page 1 … 7 8 [9] 10 11  Next page →


#67280

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-03-01 01:59 +0000
Message-ID<53113f1b$0$29985$c3e8da3$5496439d@news.astraweb.com>
In reply to#67269
On Sat, 01 Mar 2014 03:06:38 +0200, Marko Rauhamaa wrote:

> Steven D'Aprano <steve+comp.lang.python@pearwood.info>:
> 
>> I can only imagine you mean something like this:
>>
>> class Outer:
>>     class InnerOne:
>>         ...
>>
>>     class InnerTwo:
>>         ...
>>
>>     class InnerThree:
>>         ...
>>
>>
> No, I mean this:
> 
>    class StateMachine:
>        def __init__(self):
>             sm = self
> 
>             class Idle:
>                 def connect(self):
>                     ...
>                     sm.set_state(Connecting)
>                     ...
[...]


Ah, interesting. You're not just using the classes as symbols, you 
actually are giving them behaviour and using a State pattern.

But I'm not sure that there is a good reason to put the class definitions 
inside the __init__ method. That means every time you create a new 
StateMachine instance, the classes have to be re-created. (That might be 
a feature if you intend for instance1.IDLE != instance2.IDLE, but I don't 
see any good reason for that.)

It will be much more efficient if you pull all the Idle, etc. classes out 
and make them top-level global classes. Or at least stick them inside the 
StateMachine class, which means that they only get created once, and are 
shared between all StateMachine instances. But then the closure over sm 
won't work... I'll need to think some more about that.

However, the example as given won't quite work. You never instantiate the 
Idle etc. classes, which means the methods won't work. You need to make 
them class methods or static methods, or perform some metaclass magic 
prevent them from being turned into instance methods when called.

Since in this example you've actually got significant behaviour in the 
states, they aren't just symbols, and some sort of solution along these 
lines (whether you use multiple inner classes or not) is appropriate.


-- 
Steven

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


#67283

FromChris Angelico <rosuav@gmail.com>
Date2014-03-01 13:03 +1100
Message-ID<mailman.7496.1393639437.18130.python-list@python.org>
In reply to#67280
On Sat, Mar 1, 2014 at 12:59 PM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> However, the example as given won't quite work. You never instantiate the
> Idle etc. classes, which means the methods won't work. You need to make
> them class methods or static methods, or perform some metaclass magic
> prevent them from being turned into instance methods when called.

Actually, he does - setting a state means instantiating that state. I
still don't see where the benefit is, beyond that you reach the right
margin quicker than anyone else does.

ChrisA

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


#67287

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-03-01 03:29 +0000
Message-ID<53115435$0$29985$c3e8da3$5496439d@news.astraweb.com>
In reply to#67283
On Sat, 01 Mar 2014 13:03:53 +1100, Chris Angelico wrote:

> On Sat, Mar 1, 2014 at 12:59 PM, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>> However, the example as given won't quite work. You never instantiate
>> the Idle etc. classes, which means the methods won't work. You need to
>> make them class methods or static methods, or perform some metaclass
>> magic prevent them from being turned into instance methods when called.
> 
> Actually, he does - setting a state means instantiating that state.

Ah, so he does.


-- 
Steven

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


#67305

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-01 12:39 +0200
Message-ID<87wqgeqk1t.fsf@elektro.pacujo.net>
In reply to#67280
Steven D'Aprano <steve+comp.lang.python@pearwood.info>:

> But I'm not sure that there is a good reason to put the class definitions 
> inside the __init__ method. That means every time you create a new 
> StateMachine instance, the classes have to be re-created.
>
> [...]
>
> It will be much more efficient if you pull all the Idle, etc. classes out 
> and make them top-level global classes.
> [...]
> But then the closure over sm won't work...

Precisely.

As for effiency, I don't know if it is more efficient to create ad hoc
classes or ad hoc instances; might be a tossup in CPython.

> Since in this example you've actually got significant behaviour in the
> states, they aren't just symbols, and some sort of solution along
> these lines (whether you use multiple inner classes or not) is
> appropriate.

That inner class solution is an alternative to the symbol approach. In
the absense of a switch statement, the inner class has lots going for
it.


Marko

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


#67273

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-01 01:10 +0000
Message-ID<mailman.7489.1393636506.18130.python-list@python.org>
In reply to#67258
On 01/03/2014 00:03, Marko Rauhamaa wrote:
>
>> Dict dispatch tables are elegant, attractive and efficient if you are
>> using pre-existing functions or functions you can create using lambda:
>
> I beg to differ. The dict dispatch tables are very hard to read. The
> fully blown-out if-else chain beats it in elegance hands down.
>

I think you're talking nonsense.  I've been happily using dict dispatch 
tables for years and, like Steven and presumably many others, find them 
dead easy to read.  Perhaps you should invest in a better optician 
and/or glasses?

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

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

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


#67276

From"Mark H. Harris" <harrismh777@gmail.com>
Date2014-02-28 17:29 -0800
Message-ID<01310865-ae26-4249-9d15-bf6dd1b4a73a@googlegroups.com>
In reply to#67273
On Friday, February 28, 2014 7:10:49 PM UTC-6, Mark Lawrence wrote:

> I think you're talking nonsense.  I've been happily using dict dispatch 
> tables for years and, like Steven and presumably many others, find them 
> dead easy to read.  Perhaps you should invest in a better optician 
> and/or glasses?
> 

That's the rub right there...  yes, they are easy to read for someone who uses them for many years...  but not to the average coder, or scientist who just happens to be using python (like she may have used BASIC in the past, or someone else who has no idea at this stage of their python career what a dict is, let alone what a dict dispatch table is (I like to think of virtual function table myself, which its not) ... that is really the point.

Readability is important when the reader needs eye glasses...   that is the whole point in a nutshell.

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


#67253

FromBen Finney <ben+python@benfinney.id.au>
Date2014-03-01 10:17 +1100
Message-ID<mailman.7481.1393629442.18130.python-list@python.org>
In reply to#67212
Marko Rauhamaa <marko@pacujo.net> writes:

> Ben Finney <ben+python@benfinney.id.au>:
>
> > First reason: This is better done by making it clear the value is an
> > arbitrary object that won't be compared for equality. Just use
> > ‘object()’ to creeate each value and be done with it. That's a hack,
> > but it's better than pretending you'll use the string as a string of
> > text and then breaking that expectation.
[…]
> > So, I think Marko's use case is not a justification for comparing
> > string values with ‘is’.
>
> […] However, since any distinct objects will do, there is nothing
> preventing you from using string objects.

As has been pointed out to you, the whole point here is that string
objects often *are not* distinct, despite conceptually having distinct
cretion in the source.

That's why an ‘object()’ invocation is recommended: because it *will*
create distinct objects. Strings do not have that property. So strings
are *not* suitable for this use case.

-- 
 \     “It is hard to believe that a man is telling the truth when you |
  `\      know that you would lie if you were in his place.” —Henry L. |
_o__)                                                          Mencken |
Ben Finney

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


#67259

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-01 02:11 +0200
Message-ID<87k3ceeq0m.fsf@elektro.pacujo.net>
In reply to#67253
Ben Finney <ben+python@benfinney.id.au>:

> As has been pointed out to you, the whole point here is that string
> objects often *are not* distinct, despite conceptually having distinct
> cretion in the source.

You know full well that this initialization creates references to
distinct objects:

    class ABC:
        IDLE = "IDLE"
        CONNECTING = "CONNECTING"
        CONNECTED = "CONNECTED"
        DISCONNECTING = "DISCONNECTING"
        DISCONNECTED = "DISCONNECTED"

The 5 constants can (and should) be distinguished with the "is"
operator. Using "==" in this case would be slightly misleading.

You could define:

    class ABC:
        IDLE = None
        CONNECTING = 1
        CONNECTED = list
        DISCONNECTING = MyDisconnecting(9)
        DISCONNECTED = float("nan")

without changing the functionality of the state machine (as long as "is"
is used to identify the state).


Marko

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


#67266

FromBen Finney <ben+python@benfinney.id.au>
Date2014-03-01 11:50 +1100
Message-ID<mailman.7486.1393635051.18130.python-list@python.org>
In reply to#67259
Marko Rauhamaa <marko@pacujo.net> writes:

> Ben Finney <ben+python@benfinney.id.au>:
>
> > As has been pointed out to you, the whole point here is that string
> > objects often *are not* distinct, despite conceptually having distinct
> > cretion in the source.
>
> You know full well that this initialization creates references to
> distinct objects:
>
>     class ABC:
>         IDLE = "IDLE"
>         CONNECTING = "CONNECTING"
>         CONNECTED = "CONNECTED"
>         DISCONNECTING = "DISCONNECTING"
>         DISCONNECTED = "DISCONNECTED"
>
> The 5 constants can (and should) be distinguished with the "is"
> operator.

>From each other, of course they're distinct, because they are unequal.

They are *not* necessarily distinct from other strings with equal value,
defined elsewhere. That's what has been pointed out to you many times.

So, either you care about these values being distinct from all others
because you want to compare them with ‘is’ (and so strings are a poor
choice); or you don't care about that, and you should instead compare
these values with the equality operator ‘==’.

Either way, don't compare strings with ‘is’. If you want objects you can
compare reliably with ‘is’, use some other type.

-- 
 \     “Don't be afraid of missing opportunities. Behind every failure |
  `\         is an opportunity somebody wishes they had missed.” —Jane |
_o__)                                          Wagner, via Lily Tomlin |
Ben Finney

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


#67272

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-01 03:10 +0200
Message-ID<87zjlad8q4.fsf@elektro.pacujo.net>
In reply to#67266
Ben Finney <ben+python@benfinney.id.au>:

>>From each other, of course they're distinct, because they are unequal.
>
> They are *not* necessarily distinct from other strings with equal
> value, defined elsewhere. That's what has been pointed out to you many
> times.

That point is completely irrelevant. The state objects only need to be
distinct from each other. How do I know? I originally wrote the example.

> So, either you care about these values being distinct from all others
> because you want to compare them with ‘is’ (and so strings are a poor
> choice);

Strings are as good objects for the purpose as any and have some nice
advantages during troubleshooting and logging.


Marko

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


#67274

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-01 01:19 +0000
Message-ID<mailman.7490.1393636807.18130.python-list@python.org>
In reply to#67272
On 01/03/2014 01:10, Marko Rauhamaa wrote:
> Ben Finney <ben+python@benfinney.id.au>:
>
>> >From each other, of course they're distinct, because they are unequal.
>>
>> They are *not* necessarily distinct from other strings with equal
>> value, defined elsewhere. That's what has been pointed out to you many
>> times.
>
> That point is completely irrelevant. The state objects only need to be
> distinct from each other. How do I know? I originally wrote the example.
>
>> So, either you care about these values being distinct from all others
>> because you want to compare them with ‘is’ (and so strings are a poor
>> choice);
>
> Strings are as good objects for the purpose as any and have some nice
> advantages during troubleshooting and logging.
>
>
> Marko
>

How many more times do you have to be shot down before you give up?  Or 
do you intend coming back like the Phoenix, or worse still like our 
resident unicode expert, to haunt us?

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

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.
http://www.avast.com

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


#67278

FromBen Finney <ben+python@benfinney.id.au>
Date2014-03-01 12:41 +1100
Message-ID<mailman.7492.1393638091.18130.python-list@python.org>
In reply to#67272
Marko Rauhamaa <marko@pacujo.net> writes:

> Ben Finney <ben+python@benfinney.id.au>:
>
> > They are *not* necessarily distinct from other strings with equal
> > value, defined elsewhere. That's what has been pointed out to you
> > many times.
>
> That point is completely irrelevant. The state objects only need to be
> distinct from each other.

In which case, don't mislead the reader by comparing with ‘is’.

Since you don't care about identity, only that the objects have
different values, you should be comparing for equality with ‘==’.

> How do I know? I originally wrote the example.

Yes. And as the author, you're being misleading by using the identity
comparison, when you don't care about their identity by your own
admission here.

-- 
 \          Eccles: “I'll get [the job] too, you'll see. I'm wearing a |
  `\        Cambridge tie.”  Greenslade: “What were you doing there?”  |
_o__)   Eccles: “Buying a tie.” —The Goon Show, _The Greenslade Story_ |
Ben Finney

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


#67304

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-01 12:31 +0200
Message-ID<874n3irz04.fsf@elektro.pacujo.net>
In reply to#67278
Ben Finney <ben+python@benfinney.id.au>:

> Since you don't care about identity, only that the objects have
> different values, you should be comparing for equality with ‘==’.

Ok, one last attempt.

I need *identifiers*. I could simply define:

   class ABC:
       A = object()
       B = object()
       C = object()

The program would work perfectly.

Except, if it's got a bug. I know self.abc contains either A, B or C,
but which one? Printing out self.abc won't give me any help. I could
print out ABC.A, ABC.B and ABC.C and see which one matches, but that's
cumbersome.

The next variant is to use objects that have names:

   class Symbol:
       def __init__(self, name):
           self.name = name
       def __str__(self):
           return self.name

   class ABC:
       A = Symbol("A")
       B = Symbol("B")
       C = Symbol("C")


The same program still works (and still uses "is" for identity tests,
mind you).

The next realization is that the Symbol class is completely redundant as
any string object would fit the bill. Hence we can reduce the visual
clutter by simply defining:

   class ABC:
       A = "A"
       B = "B"
       C = "C"

The same program still works (and still uses "is" for identity tests,
mind you).


Marko


PS The only remaining redundancy is having to repeat the symbol name in
every assignment. If Python (like Lisp) had a builtin symbol datatype,
you wouldn't have to define anything at all but simply assign something
like this:

    self.abc = $A

where $A would be a symbol.

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


#67306

FromBen Finney <ben+python@benfinney.id.au>
Date2014-03-01 21:48 +1100
Message-ID<mailman.7506.1393670936.18130.python-list@python.org>
In reply to#67304
Marko Rauhamaa <marko@pacujo.net> writes:

> Ben Finney <ben+python@benfinney.id.au>:
>
> > Since you don't care about identity, only that the objects have
> > different values, you should be comparing for equality with ‘==’.
>
> Ok, one last attempt.
>
> I need *identifiers*.

And, as you've realised, without an Enum pattern you have the option of
using string *values* — because it's the values you want to see in error
message output.

The *identity* of the values doesn't matter. Any string of the given
value will work fine.

So don't fool the reader into thinking you actually care about object
identity; don't use ‘is’ for comparing these values. Use ‘==’, since
that's all that matters for getting a value that will work fine.

> The same program still works (and still uses "is" for identity tests,
> mind you).

You have provided no justification for using an identity test. It
confuses the matter by pretending you care about object identity, when
you *do not* as evidenced by all your arguments so far.

The equality operator ‘==’ is clearer for your purpose, and less
confusing.

-- 
 \      “[Entrenched media corporations will] maintain the status quo, |
  `\       or die trying. Either is better than actually WORKING for a |
_o__)                  living.” —ringsnake.livejournal.com, 2007-11-12 |
Ben Finney

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


#67308

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-01 13:28 +0200
Message-ID<87k3ceqhti.fsf@elektro.pacujo.net>
In reply to#67306
Ben Finney <ben+python@benfinney.id.au>:

> Use ‘==’, since that's all that matters for getting a value that will
> work fine.

You are telling me to use '==' if I choose string objects and 'is' if I
choose some other objects.

I prefer a solution that works regardless of what objects I choose for
identifiers.

There really is no taboo against string object identity if you know what
you are doing.


Marko

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


#67311

FromChris Angelico <rosuav@gmail.com>
Date2014-03-01 22:59 +1100
Message-ID<mailman.7509.1393675202.18130.python-list@python.org>
In reply to#67308
On Sat, Mar 1, 2014 at 10:28 PM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Ben Finney <ben+python@benfinney.id.au>:
>
>> Use ‘==’, since that's all that matters for getting a value that will
>> work fine.
>
> You are telling me to use '==' if I choose string objects and 'is' if I
> choose some other objects.
>
> I prefer a solution that works regardless of what objects I choose for
> identifiers.
>
> There really is no taboo against string object identity if you know what
> you are doing.

And, as proven here in this thread, you do not know what you are doing.

ChrisA

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


#67321

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-03-01 17:07 +0000
Message-ID<531213c4$0$29987$c3e8da3$5496439d@news.astraweb.com>
In reply to#67311
On Sat, 01 Mar 2014 22:59:52 +1100, Chris Angelico wrote:

> On Sat, Mar 1, 2014 at 10:28 PM, Marko Rauhamaa <marko@pacujo.net>
> wrote:
>> Ben Finney <ben+python@benfinney.id.au>:
>>
>>> Use ‘==’, since that's all that matters for getting a value that will
>>> work fine.
>>
>> You are telling me to use '==' if I choose string objects and 'is' if I
>> choose some other objects.
>>
>> I prefer a solution that works regardless of what objects I choose for
>> identifiers.
>>
>> There really is no taboo against string object identity if you know
>> what you are doing.
> 
> And, as proven here in this thread, you do not know what you are doing.

Steady on, that's a bit harsh. In context, I think that Marko is assuming 
that the caller will only ever use the state values via their symbolic 
names, e.g. only refer to them as IDLE, CONNECTED etc. and never use 
their internal string values "IDLE", "CONNECTED".

I don't think that's a safe assumption, since it requires the caller to 
only ever do the right thing, but if it is true, then using "is" in the 
way he suggests cannot fail.

Still, I've repeatedly asked Marko to justify why we should care about 
the symbols being singletons, and unless I've missed something, he hasn't 
even attempted to justify that. It seems to me that he's just assuming 
that symbols ought to be singletons, hence his focus on identity rather 
than equality.




-- 
Steven D'Aprano
http://import-that.dreamwidth.org/

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


#67324

FromChris Angelico <rosuav@gmail.com>
Date2014-03-02 04:27 +1100
Message-ID<mailman.7518.1393694852.18130.python-list@python.org>
In reply to#67321
On Sun, Mar 2, 2014 at 4:07 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> On Sat, 01 Mar 2014 22:59:52 +1100, Chris Angelico wrote:
>> And, as proven here in this thread, you do not know what you are doing.
>
> Steady on, that's a bit harsh. In context, I think that Marko is assuming
> that the caller will only ever use the state values via their symbolic
> names, e.g. only refer to them as IDLE, CONNECTED etc. and never use
> their internal string values "IDLE", "CONNECTED".

A bit harsh, perhaps, but I stand by it: by repeatedly declaring that
something is safe when it has been proven not safe, he shows that he
does not know what he is doing - that he is not fully comprehending
the significance of object value vs identity as regards strings.

Incidentally, Python somewhat creates this issue, by sometimes
interning and sometimes not. (And the same with small integers,
although I've never heard the expression "int interning".) If strings
were always interned, then it would be obvious that identity and value
were one and the same. On the flip side, if a string literal always
created a new string (that is, if it were more like a "string
construction syntax" like square brackets for lists), then it would be
obvious that each one is a separate object. I don't say either option
is worth doing (especially the latter, O!), but by sometimes merging
and sometimes not, Python does slightly blur the line between identity
and value. (Obviously if strings were mutable, they'd *have* to have
separate identities.)

> I don't think that's a safe assumption, since it requires the caller to
> only ever do the right thing, but if it is true, then using "is" in the
> way he suggests cannot fail.

If you're depending on the caller doing the right thing, it's still
safe to use == rather than is. The only reason to use 'is' is to
prevent the caller from stuffing in some other string that happens to
be correct - hence his point about being able to change the keywords.
If the caller stuffs in the string "INIT" instead of the object
Foo.INIT, then "==" will happen to work until such time as Foo.INIT
becomes "INITIALIZING", at which point it breaks. Preventing that
means that unique object identity is crucial to the system working,
and that's pretty much impossible with strings. (I don't say it's
absolutely impossible; maybe if you intern some other string with the
same value, and then construct the string you want out of pieces, and
somehow prevent the compiler from figuring out what you're doing and
optimizing it all away, then maybe you could have something that
doesn't get reused anywhere else. But it's certainly not normal to be
able to be sure of that.)

ChrisA

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


#67333

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-01 20:25 +0200
Message-ID<87iorx93o0.fsf@elektro.pacujo.net>
In reply to#67321
Steven D'Aprano <steve+comp.lang.python@pearwood.info>:

> It seems to me that he's just assuming that symbols ought to be
> singletons, hence his focus on identity rather than equality.

Yes.

A practical angle is this: if I used strings as symbols and compared
them with "==", logically I shouldn't define them as constants but
simply use strings everywhere:

   class Connection:
       def __init__(self):
           self.state = "IDLE"

       def connect(self, address):
           if self.state == "IDLE":
               ...
           elif self.state == ...

The principal (practical) problem with that is that I might make a typo
and write:

           if self.state == "IDLE ":

which could result in some hard-to-find problems. That's why I want get
the help of the Python compiler and always refer to the states through
symbolic constants:

           if self.state == self.IDLE:


Marko

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


#67383

FromBen Finney <ben+python@benfinney.id.au>
Date2014-03-02 09:30 +1100
Message-ID<mailman.7544.1393713036.18130.python-list@python.org>
In reply to#67333
Marko Rauhamaa <marko@pacujo.net> writes:

> Steven D'Aprano <steve+comp.lang.python@pearwood.info>:
>
> > It seems to me that he's just assuming that symbols ought to be
> > singletons, hence his focus on identity rather than equality.
>
> Yes.

Give that up, then. Your assumption is false in Python, and is not
needed to get the behaviour you say you need.

> A practical angle is this: if I used strings as symbols and compared
> them with "==", logically I shouldn't define them as constants but
> simply use strings everywhere

Yes, that works fine. It's also quite understandable for the reader.

> The principal (practical) problem with that is that I might make a
> typo and write:
>
>            if self.state == "IDLE ":
>
> which could result in some hard-to-find problems.

That's just one of a huge variety of problems. Write a comprehensive
unit test suite to catch this and a great many other errors.

> That's why I want get the help of the Python compiler and always refer
> to the states through symbolic constants

Python doesn't let you compare symbols, only values. Work within its
constraints.

-- 
 \     “I cannot conceive that anybody will require multiplications at |
  `\   the rate of 40,000 or even 4,000 per hour …” —F. H. Wales, 1936 |
_o__)                                                                  |
Ben Finney

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


Page 9 of 11 — ← Prev page 1 … 7 8 [9] 10 11  Next page →

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


csiph-web