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 217 — 27 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? 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 6 of 11 — ← Prev page 1 … 4 5 [6] 7 8 … 11  Next page →


#67222

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-02-28 16:26 +0200
Message-ID<87d2i7wbxs.fsf@elektro.pacujo.net>
In reply to#67220
Neil Cerutti <neilc@norwich.edu>:

> Check out Go's switch statement for an example of what it might
> look like in Python. Except you'd get it without labeled break or
> the fallthrough statement.

No need for the fallthrough (except that multiple cases should be
supported).

Labeled breaks wouldn't be needed because there are no fallthroughs.

> Would you still want to use it?

Probably.

Guile (scheme) has:

   (case (state self)
     ((CONNECTING CONNECTED)
      ...)
     ((DISCONNECTING)
      ...)
     (else
      ...))

Python isn't "averse" to the switch statement because it would be not
that useful. Rather, the problem is that Python doesn't have nonliteral
constants (scheme has builtin symbols). It is difficult to come up with
truly Pythonic syntax for the switch statement.

Something like

   switch self.state from Connection.State:
       case CONNECTING or CONNECTED:
           ...
       case DISONNECTING:
           ...
       else:
           ...

would be possible, but here, "Connection.State" is evaluated at compile
time. Don't know if there are any precedents to that kind of thing in
Python.


Marko

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


#67224

FromChris Angelico <rosuav@gmail.com>
Date2014-03-01 01:37 +1100
Message-ID<mailman.7470.1393598262.18130.python-list@python.org>
In reply to#67222
On Sat, Mar 1, 2014 at 1:26 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Python isn't "averse" to the switch statement because it would be not
> that useful. Rather, the problem is that Python doesn't have nonliteral
> constants (scheme has builtin symbols). It is difficult to come up with
> truly Pythonic syntax for the switch statement.
>
> Something like
>
>    switch self.state from Connection.State:
>        case CONNECTING or CONNECTED:
>            ...
>        case DISONNECTING:
>            ...
>        else:
>            ...
>
> would be possible, but here, "Connection.State" is evaluated at compile
> time. Don't know if there are any precedents to that kind of thing in
> Python.

Can you elaborate on this "nonliteral constants" point? How is it a
problem if DISCONNECTING isn't technically a constant? It follows the
Python convention of being in all upper-case, so the programmer
understands not to rebind it. Is the problem that someone might
(naively or maliciously) change the value of DISCONNECTING, or is the
problem that Python doesn't fundamentally know that it won't change?

ChrisA

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


#67232

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-02-28 17:29 +0200
Message-ID<877g8fgsr1.fsf@elektro.pacujo.net>
In reply to#67224
Chris Angelico <rosuav@gmail.com>:

> Can you elaborate on this "nonliteral constants" point? How is it a
> problem if DISCONNECTING isn't technically a constant? It follows the
> Python convention of being in all upper-case, so the programmer
> understands not to rebind it. Is the problem that someone might
> (naively or maliciously) change the value of DISCONNECTING, or is the
> problem that Python doesn't fundamentally know that it won't change?

This last point. It would make it impossible for Python to treat the
switch statement as anything but an alternate form of chained if-else.
A dict optimization wouldn't actually optimize anything because it would
have to be constructed every time the statement is executed.

   switch self.state from Connection.State:
       case CONNECTING or CONNECTED:
           ...
       case DISONNECTING:
           ...
       else:
           ...

would have to be transformed by Python into:

   _X1 = self.state
   _X2 = Connection.State
   if _X1 is _X2.CONNECTING or _X1 is _X2.CONNECTED:
       ...
   elif _X1 is _X2.DISCONNECTING:
       ...
   else:
       ...

So optimization is gone. Then we have the syntactic burden. Python
currently doesn't (seem to) have a syntactic precedent for such implicit
dot notation. (Note that even Java had to complicate its syntax
analogously with enums.) In "CONNECTING or CONNECTED", "or" wouldn't be
an operator in an expression but a particle.

Another syntactic oddity is the two indentation levels.

BTW, here's a syntax that doesn't introduce any new keywords:

   with self.state from Connection.State:
       if CONNECTING or CONNECTED:
           ...
       elif DISONNECTING:
           ...
       else:
           ...


Marko

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


#67234

FromChris Angelico <rosuav@gmail.com>
Date2014-03-01 02:46 +1100
Message-ID<mailman.7477.1393602403.18130.python-list@python.org>
In reply to#67232
On Sat, Mar 1, 2014 at 2:29 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> BTW, here's a syntax that doesn't introduce any new keywords:
>
>    with self.state from Connection.State:
>        if CONNECTING or CONNECTED:
>            ...
>        elif DISONNECTING:
>            ...
>        else:
>            ...

Okay, I understand your 'from' now. What it really does is introduce a
new scope, a read-only one presumably (because you really do NOT want
the Pandora's Box that ECMAScript's 'with' is) from which unqualified
names will be looked up. I would say that that's a very reasonable
idea, quite separately from a switch statement. Suppose you had
something like this:

with scope(Connection.State):
    if self.state == CONNECTING:
        print("I am not",DISCONNECTING)

It'd require a change to the LOAD_GLOBAL opcode to have it look in
multiple scopes. If you want to change something, be explicit about
where the change goes, but for lookups, it would be possible to have
them go to multiple places. I suspect, though, that this wouldn't fly;
I already posited such a theory, and was told that CPython's internals
made it much more convenient to not introduce infinitely nesting
scopes - the two use-cases that I'd most look at are these:

# This executes as a function
doubled = [x*2 for x in lst]

# This implicitly unbinds e in a finally clause
try:
    foo()
except Exception as e:
    pass

Neither is quite perfect; the closure method is mostly clean, but has
some extremely esoteric edge cases, and the unbinding means that a
previous value for 'e' is lost. But both are kept rather than
introducing this concept of true subscoping, because CPython's
implementation makes the latter hard.

Predicating your entire proposal on something that has been avoided
twice and just recently turned down, though, is a good way to get the
whole proposal rejected.

ChrisA

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


#67362

FromGrant Edwards <invalid@invalid.invalid>
Date2014-02-28 16:09 +0000
Message-ID<leqcb4$p6m$1@reader1.panix.com>
In reply to#67232
On 2014-02-28, Marko Rauhamaa <marko@pacujo.net> wrote:
> Chris Angelico <rosuav@gmail.com>:
>
>> Can you elaborate on this "nonliteral constants" point? How is it a
>> problem if DISCONNECTING isn't technically a constant? It follows the
>> Python convention of being in all upper-case, so the programmer
>> understands not to rebind it. Is the problem that someone might
>> (naively or maliciously) change the value of DISCONNECTING, or is the
>> problem that Python doesn't fundamentally know that it won't change?
>
> This last point. It would make it impossible for Python to treat the
> switch statement as anything but an alternate form of chained if-else.

There are a couple nice things about a switch () statement:

 1) It guarantees that 'expr' is evaluated exactly once.  If you want
    that with a chained if/else you have to create a temporary variable.

 2) It guarantees that exactly one path is chosen (assuming we're not
    going to duplicate C's "fall through" mistake).
    
The result is that it makes the author's intention instantly clear to
the reader: we're going to evaluate some expression _exactly_once_ and
then select _exactly_one_ of several paths based on that value.  Sure,
you can do the same thing with a chained if/elif/else, but it requires
some effort for the reader to figure that out.  Accidently type "if"
instead of "elif" two thirds of the way down, and you get something
that works right _most_ of the time, but not always.  [Not that _I've_
ever done that and then read through the whole thing six times over a
period of two days before noticing it.] :)

<reductio ad absurdum>
If the availability of an alternate but computationally equivalent
representation was a valid argument against a language feature, then
we ought to toss out Python entirely: It's always possible to write
the exact same algorithm, so why bother with Python?
</reductio ad absurdum>    

> A dict optimization wouldn't actually optimize anything because it
> would have to be constructed every time the statement is executed.

I don't think question should be "how does this help the compiler?"

The question should be "how does this help the _user_ of the compiler?

The user of the compiler spends more time reading code than anything
else.  Something that makes code easier to read is therefore worth
considering. A switch statement is easier to read than a chained
if/else.  IMO, _that's_ the proper argument for a switch statement.

Trying to justify a switch statement as a way to help generate more
efficient code seems silly: This is not 1970 -- any decent compiler
should be able to generate the same code for a switch statement and
for an equivalent chained if/else.

-- 
Grant Edwards               grant.b.edwards        Yow! I want to read my new
                                  at               poem about pork brains and
                              gmail.com            outer space ...

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


#67416

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-02 10:00 +0200
Message-ID<874n3h58t4.fsf@elektro.pacujo.net>
In reply to#67362
Grant Edwards <invalid@invalid.invalid>:

> any decent compiler should be able to generate the same code for a
> switch statement and for an equivalent chained if/else.

It's not so easy to be decent, especially when it comes to a language as
dynamic as Python.


Marko

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


#67364

FromRoy Smith <roy@panix.com>
Date2014-02-28 09:43 -0500
Message-ID<roy-590D18.09433028022014@news.panix.com>
In reply to#67222
In article <87d2i7wbxs.fsf@elektro.pacujo.net>,
 Marko Rauhamaa <marko@pacujo.net> wrote:

> Neil Cerutti <neilc@norwich.edu>:
> 
> > Check out Go's switch statement for an example of what it might
> > look like in Python. Except you'd get it without labeled break or
> > the fallthrough statement.

Python already has a switch statement.  It's just spelled funny...

class Switch(Exception): pass
class Case1(Switch): pass
class Case2(Switch): pass
class Case3(Switch): pass

try:
   raise value
except Case1:
   print "did case 1"
except (Case2, Case3):
   print "did either case 2 or 3"
else:
   print "did default"

No fall-through, however.  I'm sure with a little meta-class magic, you 
could write a Case() which eliminates the need for manually declaring 
the cases.

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


#67415

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-02 10:00 +0200
Message-ID<87bnxp58t7.fsf@elektro.pacujo.net>
In reply to#67364
Roy Smith <roy@panix.com>:

> Python already has a switch statement.  It's just spelled funny...
>
> [...]
>
> try:
>    raise value
> except Case1:
>    print "did case 1"
> except (Case2, Case3):
>    print "did either case 2 or 3"
> else:
>    print "did default"

Not bad! Definitely worth considering.

> No fall-through, however.

Fall-trough is an unfortunate C syntax accident, not a feature worth
emulating.


Marko

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


#67448

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-02 17:26 +0200
Message-ID<87fvn08vux.fsf@elektro.pacujo.net>
In reply to#67415
Marko Rauhamaa <marko@pacujo.net>:

> Roy Smith <roy@panix.com>:
>
>> Python already has a switch statement.  It's just spelled funny...
>>
>> [...]
>>
>> try:
>>    raise value
>> except Case1:
>>    print "did case 1"
>> except (Case2, Case3):
>>    print "did either case 2 or 3"
>> else:
>>    print "did default"
>
> Not bad! Definitely worth considering.

I wrote a simple test that switched between 26 "enums" using three
techniques and measured execution times (2,600,000 switching
operations). I also measured the time with no switching and subtracted
that time from the test times.

Results of the competition (performed with python3.2.3):

1. DICT DISPATCH TABLE (0.2 µs/switch)

2. IF-ELSE CHAIN (850% slower than DICT DISPATCH TABLE)

3. TRY-EXCEPT (3500% slower than DICT DISPATCH TABLE)


Marko

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


#67449

FromRoy Smith <roy@panix.com>
Date2014-03-02 10:34 -0500
Message-ID<roy-772D63.10343302032014@news.panix.com>
In reply to#67448
In article <87fvn08vux.fsf@elektro.pacujo.net>,
 Marko Rauhamaa <marko@pacujo.net> wrote:

> Marko Rauhamaa <marko@pacujo.net>:
> 
> > Roy Smith <roy@panix.com>:
> >
> >> Python already has a switch statement.  It's just spelled funny...
> >>
> >> [...]
> >>
> >> try:
> >>    raise value
> >> except Case1:
> >>    print "did case 1"
> >> except (Case2, Case3):
> >>    print "did either case 2 or 3"
> >> else:
> >>    print "did default"
> >
> > Not bad! Definitely worth considering.
> 
> [...]
> 3. TRY-EXCEPT (3500% slower than DICT DISPATCH TABLE)

I'm glad to hear that.  I hope nobody took me seriously when I suggested 
this.

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


#67450

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-02 17:52 +0200
Message-ID<87a9d88uoo.fsf@elektro.pacujo.net>
In reply to#67449
Roy Smith <roy@panix.com>:

> In article <87fvn08vux.fsf@elektro.pacujo.net>,
>  Marko Rauhamaa <marko@pacujo.net> wrote:
>> 3. TRY-EXCEPT (3500% slower than DICT DISPATCH TABLE)
>
> I'm glad to hear that. I hope nobody took me seriously when I
> suggested this.

I actually have employed the idea before in a related but slightly
different use case.

Anyway, it's extremely close to the switch statement's use case and
should give some guidance if a proper switch statement is ever worked
into the language. What's killing the performance is the backtrace
generation and longjmp trickery. If an analogous syntax could be (A)
separated from BaseException and (B) compiled into a dict, we could have
a winner.


Marko

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


#67453

FromChris Angelico <rosuav@gmail.com>
Date2014-03-03 03:23 +1100
Message-ID<mailman.7585.1393777394.18130.python-list@python.org>
In reply to#67450
On Mon, Mar 3, 2014 at 2:52 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> Roy Smith <roy@panix.com>:
>
>> In article <87fvn08vux.fsf@elektro.pacujo.net>,
>>  Marko Rauhamaa <marko@pacujo.net> wrote:
>>> 3. TRY-EXCEPT (3500% slower than DICT DISPATCH TABLE)
>>
>> I'm glad to hear that. I hope nobody took me seriously when I
>> suggested this.
>
> I actually have employed the idea before in a related but slightly
> different use case.
>
> Anyway, it's extremely close to the switch statement's use case and
> should give some guidance if a proper switch statement is ever worked
> into the language. What's killing the performance is the backtrace
> generation and longjmp trickery. If an analogous syntax could be (A)
> separated from BaseException and (B) compiled into a dict, we could have
> a winner.

The trouble is, try/except fundamentally can't be compiled into a
dict, because Python's exception handling is based on subclasses.

try: func()
except FileNotFoundError: pass
except OSError: raise RuntimeError("Oops")
except Exception as e: log(e)
except: log("Aborting!"); raise
finally: log("Done")

How would you handle that with a dict? It's inherently ordered - a
FileNotFoundError would be caught by any one of those clauses, and
since there's no sane way to "pick the narrowest", the best way to
handle it is sequential evaluation. (Also, it's worth noting that
exception lists are not constants. It's possible to do downright
insane things like calling a function to figure out what exceptions to
handle. Yeah, that's pretty stupid, right there.)

A switch block that works with constants and equality *can* be turned
into a dict. If the constants are hashable, use them as the keys
directly; if they're not hashable and/or you want to use object
identity as the criterion (effectively like using 'is' rather than
'==' for your case statements), use id(x) as the keys, and make sure
you have other references to the objects. Then it'll be fine as a
straight-up dict.

If the switch block uses inequalities, then it suffers from the same
problem as the try/except block - it's inherently ordered, in case
(pun intended) there's a switched-on value that matches more than one.
(You could possibly optimize the int case, but that would be way WAY
too specific for a generic language structure.)

ChrisA

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


#67456

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-02 16:53 +0000
Message-ID<mailman.7586.1393779205.18130.python-list@python.org>
In reply to#67450
On 02/03/2014 16:23, Chris Angelico wrote:
>
> A switch block that works with constants and equality *can* be turned
> into a dict. If the constants are hashable, use them as the keys
> directly; if they're not hashable and/or you want to use object
> identity as the criterion (effectively like using 'is' rather than
> '==' for your case statements), use id(x) as the keys, and make sure
> you have other references to the objects. Then it'll be fine as a
> straight-up dict.
>
> If the switch block uses inequalities, then it suffers from the same
> problem as the try/except block - it's inherently ordered, in case
> (pun intended) there's a switched-on value that matches more than one.
> (You could possibly optimize the int case, but that would be way WAY
> too specific for a generic language structure.)
>
> ChrisA
>

You clearly don't get my point.  I *DON'T* want to use stupid constants 
and stupid equalities, I want to use identities.  I *DON'T* want to use 
stupid ==, I want to use 'is'.  I *DON'T* care how many people with 
years of experience of Python tell me that this is the wrong thing to 
do, that is how I am going to do it.  So, for the final time of asking, 
how do I do the above with, and only with, the identity, even if you 
stupidly keep on trying to tell me that this is wrong?

-- 
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]


#67229

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-02-28 15:06 +0000
Message-ID<mailman.7474.1393600021.18130.python-list@python.org>
In reply to#67216
On 28/02/2014 11:38, Marko Rauhamaa wrote:
> Switch statements provide for excellent readability in parsers and state
> machines, for example. They also allow the Python compiler to optimize
> the statement internally unlike long if-else chains.
>

There are umpteen recipes for switch statements so take your pick or if 
you don't like any of them write your own.  Much easier than beating 
your head against multiple brick walls, which is what raising this one 
on python-ideas is likely to be.  See 
http://legacy.python.org/dev/peps/pep-0275/ and 
http://legacy.python.org/dev/peps/pep-3103/

-- 
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]


#67236

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-02-28 15:50 +0000
Message-ID<5310b031$0$29985$c3e8da3$5496439d@news.astraweb.com>
In reply to#67212
On Fri, 28 Feb 2014 12:02:03 +0200, Marko Rauhamaa wrote:

> PS On the topic of enums, when are we getting support for a switch
> statement?

http://legacy.python.org/dev/peps/pep-3103/

http://legacy.python.org/dev/peps/pep-0275/



-- 
Steven

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


#67237

From"Mark H. Harris" <harrismh777@gmail.com>
Date2014-02-28 10:04 -0800
Message-ID<db181305-97fe-4385-bf11-5323d4bd1160@googlegroups.com>
In reply to#67236
On Friday, February 28, 2014 9:50:09 AM UTC-6, Steven D'Aprano wrote:

> > PS On the topic of enums, when are we getting support for a switch
> > statement?

> http://legacy.python.org/dev/peps/pep-3103/
> http://legacy.python.org/dev/peps/pep-0275/
> 

I have reviewed these peps, and I heard Guido's 2007 keynote, as well I have heard him speak on YouTube several times about the inadvisability of a pythonized  switch statement (similar to C). 

I think the real issue is about the syntax... because of python's unique indent strategy going back to ABC, a pythonized switch statement would play havoc with the many text parsers out there used for development (TestWrangler, and many others). 

Personally I would still like to see a pythonized switch statement at some point.  I prefer the syntactical form of PEP 275,   but unlike the notion of dropping optimization and converting to if elif else under the proverbial covers,  I would prefer to see a conversion to the dict dispatch table under the covers. 

At any rate...  and I don't think even Guido can really argue against this,...   a switch statement is just more readable to human beings that a dict dispatch table, or a long if elif chain... and one of the main points of python (going all the way back to ABC) was to make very highly readable code.

marcus

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


#67242

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-02-28 20:53 +0200
Message-ID<87iorzf4ro.fsf@elektro.pacujo.net>
In reply to#67237
"Mark H. Harris" <harrismh777@gmail.com>:

> I think the real issue is about the syntax... because of python's
> unique indent strategy going back to ABC, a pythonized switch
> statement would play havoc with the many text parsers out there used
> for development (TestWrangler, and many others).

I also took a look at the proposals. I don't think it's the editor
issue. The variant I proposed most recently:

   with self.state from Connection.State:
       if CONNECTING or CONNECTED:
           ...
       elif DISONNECTING:
           ...
       else:
           ...

would be handled gracefully by all sane python editors, I believe.

The main problem is that it can't be optimized effectively without
bringing in an element of preprocessing. That preprocessing is done by
the human developer with the dict dispatch table, but nothing in regular
Python gives the compiler enough guaranteed information to build the
dispatch table. There are ways to be smart, but it would be a lot of
additional code for the compiler for a questionable performance gain.

> a switch statement is just more readable to human beings that a dict
> dispatch table, or a long if elif chain... and one of the main points
> of python (going all the way back to ABC) was to make very highly
> readable code.

A dict dispatch table is just awful. At least have the decency of
creating inner classes.

... which brings up the point for another post...


Marko

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


#67243

FromChris Angelico <rosuav@gmail.com>
Date2014-03-01 05:59 +1100
Message-ID<mailman.7479.1393613988.18130.python-list@python.org>
In reply to#67242
On Sat, Mar 1, 2014 at 5:53 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> A dict dispatch table is just awful.

Really? How is that? I've used them, often. Yes, there are times when
I could express something more cleanly with a C-style switch
statement, but other times the dispatch table is fundamentally
cleaner. I shared an example a few posts ago in this thread; care to
elaborate on how it's "just awful"?

ChrisA

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


#67244

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-02-28 21:20 +0200
Message-ID<877g8ff3hn.fsf@elektro.pacujo.net>
In reply to#67243
Chris Angelico <rosuav@gmail.com>:

> On Sat, Mar 1, 2014 at 5:53 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
>> A dict dispatch table is just awful.
>
> Really? How is that? I've used them, often. Yes, there are times when
> I could express something more cleanly with a C-style switch
> statement, but other times the dispatch table is fundamentally
> cleaner. I shared an example a few posts ago in this thread; care to
> elaborate on how it's "just awful"?

Your example:

    compare_key = {
        # Same target(s).
        ast.Assign: lambda node: ' '.join(dump(t) for t in node.targets),
        # Same target and same operator.
        ast.AugAssign: lambda node: dump(node.target) + dump(node.op) + "=",
        # A return statement is always compatible with another.
        ast.Return: lambda node: "(easy)",
        # Calling these never compatible is wrong. Calling them
        # always compatible will give lots of false positives.
        ast.Expr: lambda node: "(maybe)",
        # These ones are never compatible, so return some
        # object that's never equal to anything.
        ast.Import: lambda node: float("nan"),
        ast.ImportFrom: lambda node: float("nan"),
        ast.Pass: lambda node: float("nan"),
        ast.Raise: lambda node: float("nan"),
        ast.If: lambda node: float("nan"),
    }

vs (my proposal):

    with key from ast:
        if Assign:
            return ' '.join(dump(t) for t in node.targets)
        elif AugAssign:
            # Same target and same operator.
            return dump(node.target) + dump(node.op) + "="
        elif Return:
            # A return statement is always compatible with another.
            return "(easy)"
        elif Expr:
            # Calling these never compatible is wrong. Calling them
            # always compatible will give lots of false positives.
            return "(maybe)"
        else:
            # These ones are never compatible, so return some
            # object that's never equal to anything.
            return float("nan")

Which do *you* find more readable?


Marko

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


#67248

From"Mark H. Harris" <harrismh777@gmail.com>
Date2014-02-28 12:22 -0800
Message-ID<d5984405-9ad5-4514-98cf-1914a1de7bc8@googlegroups.com>
In reply to#67244
On Friday, February 28, 2014 1:20:52 PM UTC-6, Marko Rauhamaa wrote:

> 
> Which do *you* find more readable?
> 

Yep, my point exactly.  nice illustration.

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


Page 6 of 11 — ← Prev page 1 … 4 5 [6] 7 8 … 11  Next page →

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


csiph-web