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 8 of 11 — ← Prev page 1 … 6 7 [8] 9 10 11  Next page →


#67375

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-01 22:01 +0000
Message-ID<mailman.7537.1393711293.18130.python-list@python.org>
In reply to#67374
On 01/03/2014 21:40, Mark H. Harris wrote:
> On Saturday, March 1, 2014 12:24:15 AM UTC-6, Chris Angelico wrote:
>> much code. If you want to change anything, you potentially have to
>>
>> edit three places: the list of constants at the top, the condition
>>
>> function, and the switch.
>>
>>
>>
>> This can't be your idea of readability. Show me where I'm wrong.
>>
>>
>>
>> ChrisA
>
> hi Chris,  I don't think you're wrong.  There are two issues for me (and one of them is not how the switch is implemented).
>
> 1) Is it easier for average users of python as a language to read switch case default,  or if elif else ?
>
> 2) Would most average users concur that 'readable' means something like, "readily understandable at quick glance, or rapid preview" (or quiv).
>
> I readily admit that 'subjective' is the operative work here. As Guido found at his 2007 keynote most experienced devs are not clamoring for a switch block. Just so. But I'm not thinking of experienced devs. I'm thinking of the average coder who is used to looking at switch blocks.
>
> I personally can see and understand a switch block 2x to 3x faster than looking at an elif chain. Because I am primarily a C programmer and I personally use and read switch blocks.
>
> An experienced python dev can readily 'see' an elif chain, well, because that's all they have and that's all they look at day to day.  So, naturally a python dev is going to think an elif chain is readable.
>
> Thank you sir, you have good insights. A quote from the high seas is classy.
>
> (another post with no elipses)
>
> Cheers
>

No elipses, just the paragraphs not wrapped and the double line spacing. 
  Good old gg, I just love it.

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


#67377

From"Mark H. Harris" <harrismh777@gmail.com>
Date2014-03-01 14:07 -0800
Message-ID<b50d1c92-deab-481b-bc06-73b32cccd822@googlegroups.com>
In reply to#67375
On Saturday, March 1, 2014 4:01:12 PM UTC-6, Mark Lawrence wrote:

> 
> No elipses, just the paragraphs not wrapped and the double line spacing. 
> 
>   Good old gg, I just love it.

How do I fix it?   Is there a setting someplace?  I tried pulling up the page you linked, but blank.

Thanks in advance.

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


#67392

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-01 23:21 +0000
Message-ID<mailman.7550.1393716131.18130.python-list@python.org>
In reply to#67377
On 01/03/2014 22:07, Mark H. Harris wrote:
> On Saturday, March 1, 2014 4:01:12 PM UTC-6, Mark Lawrence wrote:
>
>>
>> No elipses, just the paragraphs not wrapped and the double line spacing.
>>
>>    Good old gg, I just love it.
>
> How do I fix it?   Is there a setting someplace?  I tried pulling up the page you linked, but blank.
>
> Thanks in advance.
>

https://wiki.python.org/moin/GoogleGroupsPython

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


#67393

From"Mark H. Harris" <harrismh777@gmail.com>
Date2014-03-01 16:23 -0800
Message-ID<268ea8b1-85a8-4b41-bbe2-b8a13ca0a469@googlegroups.com>
In reply to#67392
On Saturday, March 1, 2014 5:21:57 PM UTC-6, Mark Lawrence wrote:

> https://wiki.python.org/moin/GoogleGroupsPython

Thanks, Mark.  Whoohoo! Looks like gg has some work to do. rats(). Ok, so I'm typing away here and when
I get to the boarder I should press the enter key so that the text is forced to wrap to the next line so that
you don't see the text as a run-off the page nuisance and complete annoyance leading to homicidal rage
and/or other illicit behaviors like nail-biting. 
How does this look on your news client. I just need to setup an nntp server and use a real client.

Thanks for your input Mark. 

Peace.   marcus 

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


#67394

FromChris Angelico <rosuav@gmail.com>
Date2014-03-02 11:28 +1100
Message-ID<mailman.7551.1393720127.18130.python-list@python.org>
In reply to#67393
On Sun, Mar 2, 2014 at 11:23 AM, Mark H. Harris <harrismh777@gmail.com> wrote:
> On Saturday, March 1, 2014 5:21:57 PM UTC-6, Mark Lawrence wrote:
>
>> https://wiki.python.org/moin/GoogleGroupsPython
>
> Thanks, Mark.  Whoohoo! Looks like gg has some work to do. rats(). Ok, so I'm typing away here and when
> I get to the boarder I should press the enter key so that the text is forced to wrap to the next line so that
> you don't see the text as a run-off the page nuisance and complete annoyance leading to homicidal rage
> and/or other illicit behaviors like nail-biting.
> How does this look on your news client. I just need to setup an nntp server and use a real client.

The usual recommendation is to wrap to 70-80 characters. Most likely
you're seeing a proportionally-spaced font, so going for the border of
the display is going to be inherently sloppy.

What I would recommend, if you don't feel like setting up NNTP, is to
subscribe to the mailing list:

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

All the same content, but via email instead. Take your pick between
that and a newsreader - whichever's easier to get to work.

ChrisA

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


#67395

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-02 00:36 +0000
Message-ID<mailman.7552.1393720581.18130.python-list@python.org>
In reply to#67393
On 02/03/2014 00:23, Mark H. Harris wrote:
> On Saturday, March 1, 2014 5:21:57 PM UTC-6, Mark Lawrence wrote:
>
>> https://wiki.python.org/moin/GoogleGroupsPython
>
> Thanks, Mark.  Whoohoo! Looks like gg has some work to do. rats(). Ok, so I'm typing away here and when
> I get to the boarder I should press the enter key so that the text is forced to wrap to the next line so that
> you don't see the text as a run-off the page nuisance and complete annoyance leading to homicidal rage
> and/or other illicit behaviors like nail-biting.
> How does this look on your news client. I just need to setup an nntp server and use a real client.
>
> Thanks for your input Mark.
>
> Peace.   marcus
>

I love it when a plan comes together :)

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


#67398

FromNed Deily <nad@acm.org>
Date2014-03-01 16:55 -0800
Message-ID<mailman.7554.1393721769.18130.python-list@python.org>
In reply to#67393
In article 
<CAPTjJmqgh5-n8Fgki+VMd8gRzCW5np64kinKa9_B6eWf8Gv_nA@mail.gmail.com>,
 Chris Angelico <rosuav@gmail.com> wrote:
> What I would recommend, if you don't feel like setting up NNTP, is to
> subscribe to the mailing list:
> 
> https://mail.python.org/mailman/listinfo/python-list
> 
> All the same content, but via email instead. Take your pick between
> that and a newsreader - whichever's easier to get to work.

Or use one of the multiple interfaces to the group/list provided by 
gmane.org: nntp, web, or (read-only) rss.

http://dir.gmane.org/gmane.comp.python.general

-- 
 Ned Deily,
 nad@acm.org

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


#67400

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-02 01:15 +0000
Message-ID<mailman.7556.1393722946.18130.python-list@python.org>
In reply to#67393
On 02/03/2014 00:55, Ned Deily wrote:
> In article
> <CAPTjJmqgh5-n8Fgki+VMd8gRzCW5np64kinKa9_B6eWf8Gv_nA@mail.gmail.com>,
>   Chris Angelico <rosuav@gmail.com> wrote:
>> What I would recommend, if you don't feel like setting up NNTP, is to
>> subscribe to the mailing list:
>>
>> https://mail.python.org/mailman/listinfo/python-list
>>
>> All the same content, but via email instead. Take your pick between
>> that and a newsreader - whichever's easier to get to work.
>
> Or use one of the multiple interfaces to the group/list provided by
> gmane.org: nntp, web, or (read-only) rss.
>
> http://dir.gmane.org/gmane.comp.python.general
>

This mechanism has the added advantage of being a one stop shop.  Not 
only can you subscribe to hundreds of Python lists there is also a setup 
that lets you take feeds from numerous Python blogs.

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


#67379

FromChris Angelico <rosuav@gmail.com>
Date2014-03-02 09:11 +1100
Message-ID<mailman.7540.1393711890.18130.python-list@python.org>
In reply to#67374
On Sun, Mar 2, 2014 at 8:40 AM, Mark H. Harris <harrismh777@gmail.com> wrote:
> hi Chris,  I don't think you're wrong.  There are two issues for me (and one of them is not how the switch is implemented).
>
> 1) Is it easier for average users of python as a language to read switch case default,  or if elif else ?
>
> I personally can see and understand a switch block 2x to 3x faster than looking at an elif chain. Because I am primarily a C programmer and I personally use and read switch blocks.

Sure. But before you can ask us to consider how readable it is, we
need to have comparisons. Mock up a switch statement equivalent and
show us how it'd be better. I just looked at your version, and
couldn't see any way that it would be an improvement, because it
required that there be the exact same if/elif chain to figure out what
to switch on. So give us your readable version, in an exact
reimplementation of the if/elif chain, so we can see exactly how it
would go.

ChrisA

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


#67284

FromNed Batchelder <ned@nedbatchelder.com>
Date2014-02-28 21:15 -0500
Message-ID<mailman.7497.1393640151.18130.python-list@python.org>
In reply to#67271
On 2/28/14 8:08 PM, Mark H. Harris wrote:
> On Friday, February 28, 2014 6:40:06 PM UTC-6, Ned Batchelder wrote:
>
>>
>> I don't understand: you show an if/elif chain that cannot be expressed
>> as a switch statement (because it uses < ), and then conclude that
>> Python needs a switch statement?  That doesn't make any sense.
>>
>
> Forgive me.  I would rewrite the structure,
>
>     switch x:
>        case GT_1:
>            __atan__Gt_1__(x)
>        case LT_1:
>           __atan__Lt_1__(x)
>        case IS_1:
>           a = gpi/4
>        case IS_n1:
>           a = -gpi/4
>        default:
>           __atan__(x)
>
>   or somesuch...   way better...  yes, there are some issues, but all workable with some effort
>

Mark, if you are going to advocate for a feature, find a good use case, 
this one is absurd.  Where did the constants GT_1 etc, come from?

-- 
Ned Batchelder, http://nedbatchelder.com

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


#67289

From"Mark H. Harris" <harrismh777@gmail.com>
Date2014-02-28 20:36 -0800
Message-ID<dc347784-80c6-4cbd-be60-0f6110337304@googlegroups.com>
In reply to#67284
On Friday, February 28, 2014 8:15:38 PM UTC-6, Ned Batchelder wrote:

> Mark, if you are going to advocate for a feature, find a good use case, 
> this one is absurd.  Where did the constants GT_1 etc, come from?

Not at all.   Think of the C switch block... if you read about it in the K & R you'll think its useless...  because it can only switch on a SINGLE character. So, to make it work what do you do???  You create some constants that are actually really and totally just a number... one character... that represents  GT_1  or anything else.

The switch block "switches" on a character in C.   In python it could switch on absolutely anything we like... the point is not how it switches... but how it "looks" to human beings, and "maybe" how it performs. 

For me its more important that code be readable first and foremost... then optimized.   Yes, I can use if elif else   blocks and I can and do use dict dispatch tables.... but I "wish" there were a switch case default block in python so that some things could be coded to be clearer to a human reader.

just sayin...   not arguing though...   just a comment.

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


#67270

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-03-01 01:07 +0000
Message-ID<mailman.7488.1393636068.18130.python-list@python.org>
In reply to#67256
On 01/03/2014 00:40, Ned Batchelder wrote:
> On 2/28/14 6:36 PM, Mark H. Harris wrote:
>> On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote:
>>>
>>> Marko
>>
>>     ...  and between me and you, here is a snip from dmath.py from the
>> atan(x) function:
>>
>>      if (n**2 < D(1)):
>>          a = __atan__(n)
>>      elif (n == D(1)):
>>          a = gpi/4
>>      elif (n == D(-1)):
>>          a = -(gpi/4)
>>      elif (n < D(-1)):
>>          a = __atan__Lt_neg1__(n)
>>      else:
>>          a = __atan__Gt_1__(n)
>>
>>     This if--elif--else  is not only ugly, its just not readable
>> either, and besides that, its not elegant, nor is it humanly
>> helpful...   its does work though, and its absolutely necessary.   ugh.
>>
>>     First, its not immediately clear what it does. Well, there isn't
>> just one atan(x) routine,  there are at least four of them, depending
>> on whether you're a purist, and they must be selected.
>>
>>     Second, because of the strict intent ideology of python in the
>> first place, I can't indent this code to make it more readable without
>> breaking python's syntax.
>>
>>     Third, this is a VERY simple if elif block.  More complex ones are
>> much worse... for human reading that is...
>>
>>       I know its a pain in the neck, but python does need a switch
>> statement.   Is it a stubborn question?  I don't really think that
>> almost every modern computer language has a switch block because of
>> some C paradigm. I think its because most coders find them useful, at
>> least readable, and therefore essential.
>
> I don't understand: you show an if/elif chain that cannot be expressed
> as a switch statement (because it uses < ), and then conclude that
> Python needs a switch statement?  That doesn't make any sense.
>

What a sneaky trick, trying to confuse people here with mere *FACTS* :)

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


#67286

FromGregory Ewing <greg.ewing@canterbury.ac.nz>
Date2014-03-01 16:10 +1300
Message-ID<bnd1cbF7tu5U2@mid.individual.net>
In reply to#67256
Mark H. Harris wrote:

>     if (n**2 < D(1)):
>         a = __atan__(n)
>     elif (n == D(1)):
>         a = gpi/4
>     elif (n == D(-1)):
>         a = -(gpi/4)
>     elif (n < D(-1)):
>         a = __atan__Lt_neg1__(n)
>     else:
>         a = __atan__Gt_1__(n)

That's not a candidate for a switch statement, because
the comparisons are not all equality comparisons.

-- 
Greg

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


#67367

FromRoy Smith <roy@panix.com>
Date2014-02-28 19:02 -0500
Message-ID<roy-9B8DE9.19024428022014@news.panix.com>
In reply to#67256
In article <0b414429-74ee-45dd-9465-c87e98c362f2@googlegroups.com>,
 "Mark H. Harris" <harrismh777@gmail.com> wrote:

> On Friday, February 28, 2014 3:03:25 PM UTC-6, Marko Rauhamaa wrote:
> > 
> > Marko
> 
>    ...  and between me and you, here is a snip from dmath.py from the atan(x) 
>    function:
> 
>     if (n**2 < D(1)):
>         a = __atan__(n)
>     elif (n == D(1)):
>         a = gpi/4
>     elif (n == D(-1)):
>         a = -(gpi/4)
>     elif (n < D(-1)):
>         a = __atan__Lt_neg1__(n)
>     else:
>         a = __atan__Gt_1__(n)
> 
>    This if--elif--else  is not only ugly, its just not readable either, and 
>    besides that, its not elegant, nor is it humanly helpful...   its does 
>    work though, and its absolutely necessary.   ugh.
> 
>    First, its not immediately clear what it does. Well, there isn't just one 
>    atan(x) routine,  there are at least four of them, depending on whether 
>    you're a purist, and they must be selected.

This kind of stuff is pretty common in numerical code.  Depending on the 
sign/magnitude/quadrant/whatever of the argument, you'll want to use one 
of several algorithms to minimize roundoff error, etc.

But, how would this be any nicer with switch?

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


#67254

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-02-28 23:33 +0000
Message-ID<53111ccb$0$29985$c3e8da3$5496439d@news.astraweb.com>
In reply to#67244
On Fri, 28 Feb 2014 21:20:52 +0200, Marko Rauhamaa wrote:

> Your example:
[snip]

I'm not going to show the example as quoted by you, because my news 
client is wrapping it in ugly ways and I don't want to spend the time 
fixing it. I'll just say that, as given, it's a great big wall of text, a 
solid and ugly block, but can be easily fixed to be more readable and 
look more like a switch with a judicious amount of indentation:

    compare_key = {
        ast.Assign: 
            # Same target(s).
            lambda node: ' '.join(dump(t) for t in node.targets),
        ast.AugAssign: 
            # Same target and same operator.
            lambda node: dump(node.target) + dump(node.op) + "=",
        ast.Return: 
            # A return statement is always compatible with another.
            lambda node: "(easy)",
        ast.Expr: 
            # Calling these never compatible is wrong. Calling them
            # always compatible will give lots of false positives.
            lambda node: "(maybe)",
        }

which compares favourably with your version:


>     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)"


I've deliberately dropped out  "else" clause, because the two code 
snippets as shown by you don't do the same thing. The dict dispatch table 
shown initially lists the remaining keys allowed:

    ast.Import, ast.ImportFrom, ast.Pass, ast.Raise, ast.If

and sets them all individually to five different but equivalent 
functions, lambda node: float("nan"). This is both good and bad: good, 
because it enumerates precisely what keys are expected, and will fail if 
given an unexpected value; bad because it requires repeating yourself 
five times to give the five keys the same function:

    ast.Import:
        lambda node: float("nan"),
    ast.ImportFrom:
        lambda node: float("nan"),

etc. (Actually five different functions which happen to do exactly the 
same thing.) On the other hand, your with...if...elif version simply uses 
a single "else" statement, which means it will accept *any other value at 
all*, not just the five keys accepted by Chris' version. So there is a 
semantic difference between the two.

In practice, sometimes you want a strict dispatch table that raises an 
error when given something unexpected, other times nothing is unexpected 
and you want an "else" or "otherwise" clause that captures everything. 
There are all sorts of ways to handle this in practice, e.g. using 
defaultdict, or subclassing dict and giving it a __missing__ method, or 
simply deal with the default case outside of the table itself:

    # instead of this
    dispatch[key](node)

    # do this
    dispatch.get(key, lambda node: float('nan'))(node)


> Which do *you* find more readable?

With proper code layout, the dict-based dispatch table is at least as 
readable, and it avoids needing any magic compiler support.



-- 
Steven

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


#67279

FromChris Angelico <rosuav@gmail.com>
Date2014-03-01 12:50 +1100
Message-ID<mailman.7493.1393638625.18130.python-list@python.org>
In reply to#67244
On Sat, Mar 1, 2014 at 6:20 AM, Marko Rauhamaa <marko@pacujo.net> wrote:
> 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?

Your proposal requires that I wrap the whole thing up in a function,
or else pass the lookup key to my function every time and switch on
it, instead of getting back a single function once. So you haven't
truly matched the functionality, which means it's hard to compare
readability - I'd have to also look at how readable the call site is,
and that's definitely going to be penalized. Remember, I pointed out
that the function gets called more than once - once on the special
case and then once in a loop.

Plus, how do you implement mutability? The else clause needs to do a
one-off print to stderr, so either the dispatch table needs to be
changed, or the else clause needs some other system of keeping track
of its previously-seen list. Additionally, I have another script that
actually monkey-patches the Expr case out, simply by changing the
dict. It works just fine, because, again, the dict is mutable. To do
that with a switch statement, I'd need to put an explicit 'if' into
there. Show me that version and let's see how readable it is.

There may be a case (pun intended) for adding a switch block to
Python, but this isn't a strong supporting instance.

ChrisA

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


#67251

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-02-28 23:04 +0000
Message-ID<531115e1$0$29985$c3e8da3$5496439d@news.astraweb.com>
In reply to#67242
On Fri, 28 Feb 2014 20:53:15 +0200, Marko Rauhamaa wrote:

> "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. 

You can't have it both ways: you cannot claim that switch or case is more 
readable than a chain of if...elif, and then propose a syntax which is 
effectively a chain of if...elif while still claiming it is an 
improvement. It's not. All you've done is introduce an element of 
implicit magic to the syntax.



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

Why (how?) would you want to use *multiple* classes for a single switch?

Dict dispatch tables are elegant, attractive and efficient if you are 
using pre-existing functions or functions you can create using lambda:

dispatch = {
    BLUE: handle_blue,
    RED: lambda arg: process(arg, this, that),
    ...
    }

dispatch[key](something)

It gets unwieldy if the functions don't already exist and cannot be 
embedded as a single expression. In that case, there are two simple 
approaches for when your switch cases are strings:

- move the functions into a class, as self-less methods, then use 
  the class __dict__ as the dispatch table;

- or move the functions into an external module, and use the module
  __dict__ as the dispatch table.


Even when you're not switching on strings, with the aid of a simple 
helper function, it's trivial:

dispatch = {}
def case(*args):
    def decorator(func):
        for a in arg:
            dispatch[a] = func
        return func
    return decorator


class Dispatch:
    @case(BLUE)
    def handle_blue(something):
        ...

    @case(RED):
    def handle_red(something):
        ...


dispatch[BLUE](something)


There are all sorts of simple and neat ways to handle switches in Python. 
That's why the pressure on the language to grow special syntax is quite 
low. It simply isn't important enough.



-- 
Steven

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


#67258

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

> You can't have it both ways: you cannot claim that switch or case is
> more readable than a chain of if...elif, and then propose a syntax
> which is effectively a chain of if...elif while still claiming it is
> an improvement. It's not. All you've done is introduce an element of
> implicit magic to the syntax.

You may be right that Python has too many practical problems for a truly
fitting switch syntax.

> Why (how?) would you want to use *multiple* classes for a single
> switch?

Well, I was just given a whole link on the very topic:

   <URL: http://c2.com/cgi/wiki?SwitchStatementsSmell>

Here's a shorter one:

   <URL: http://en.wikipedia.org/wiki/State_pattern>


Anyway, while implementing states as singleton inner class instances is
elegant and highly readable, the technique suffers in one significant
respect: it can be very slow. Often a state machine has numerous states
but the typical execution path only visits a few of them. However, the
pattern calls for declaring classes (or instances) for all states in the
state machine constructor. Switch statements make it possible to avoid
this creation overhead.

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

> There are all sorts of simple and neat ways to handle switches in
> Python. That's why the pressure on the language to grow special syntax
> is quite low. It simply isn't important enough.

Of course the threshold for new syntax should be exceptionally high.
Python as a language is already close to the sweet spot.


Marko

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


#67265

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-03-01 00:44 +0000
Message-ID<53112d71$0$29985$c3e8da3$5496439d@news.astraweb.com>
In reply to#67258
On Sat, 01 Mar 2014 02:03:51 +0200, Marko Rauhamaa wrote:

> Steven D'Aprano <steve+comp.lang.python@pearwood.info>:
> 
>> You can't have it both ways: you cannot claim that switch or case is
>> more readable than a chain of if...elif, and then propose a syntax
>> which is effectively a chain of if...elif while still claiming it is an
>> improvement. It's not. All you've done is introduce an element of
>> implicit magic to the syntax.
> 
> You may be right that Python has too many practical problems for a truly
> fitting switch syntax.

I didn't make that claim. My claim is that your suggested syntax is no 
real improvement over existing syntax.


>> Why (how?) would you want to use *multiple* classes for a single
>> switch?
> 
> Well, I was just given a whole link on the very topic:
> 
>    <URL: http://c2.com/cgi/wiki?SwitchStatementsSmell>

No no no, you've deleted the context. I'm not talking about making a 
switch statement unnecessary by using polymorphism. I was responding to 
your claim that instead of using a dict, one should:

    [quote]
    At least have the decency of creating inner classes.
    [end quote]

I don't understand this. That's why I asked why and how. I can only 
imagine you mean something like this:

class Outer:
    class InnerOne:
        ...

    class InnerTwo:
        ...

    class InnerThree:
        ...


but I don't see how you get from that to the functionality of a dispatch 
table, or what you're supposed to do with the nested classes.


> Here's a shorter one:
> 
>    <URL: http://en.wikipedia.org/wiki/State_pattern>

That's not a way of implementing switching. That's a way of *avoiding* 
switching. Despite the name, it has little to do with state machines.


> Anyway, while implementing states as singleton inner class instances is
> elegant and highly readable, 

O_o

That's terribly, terribly inelegant. Why not use the class objects 
themselves, instead of instantiating them? Even then, you haven't escaped 
the use of a dict dispatch table, or a chain of if...elif. You've just 
defined the symbols you use.


> the technique suffers in one significant
> respect: it can be very slow. 

Particularly if you program Java in Python.



> Often a state machine has numerous states
> but the typical execution path only visits a few of them. However, the
> pattern calls for declaring classes (or instances) for all states in the
> state machine constructor. Switch statements make it possible to avoid
> this creation overhead.

How do you avoid creating the classes or instances? If they haven't been 
created, how can the compiler reference them?



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

Only if you lay out the dict badly. Poorly written code is ugly and hard 
to read no matter what you do.



-- 
Steven

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


#67269

FromMarko Rauhamaa <marko@pacujo.net>
Date2014-03-01 03:06 +0200
Message-ID<874n3ienhd.fsf@elektro.pacujo.net>
In reply to#67265
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)
                    ...

            class Connecting:
                def poll(self):
                    if sm.sock....:
                        sm.set_state(Connected)

            class Connected:
                ...

            self.set_state(Idle)

        def set_state(self, state):
            self.state = state()

        def connect(self):
            self.state.connect()

        def poll(self):
            self.state.poll()

        ...

>> Often a state machine has numerous states but the typical execution
>> path only visits a few of them. However, the pattern calls for
>> declaring classes (or instances) for all states in the state machine
>> constructor. Switch statements make it possible to avoid this
>> creation overhead.
>
> How do you avoid creating the classes or instances? If they haven't
> been created, how can the compiler reference them?

The comparison is between three techniques:

 1. dict dispatch -- considered barely readable by me

 2. the state pattern (see "class StateMachine" above)

 3. sentinel state objects with switches

What I said in the above paragraph is that state machines can be written
using the state pattern (thus avoiding the need for switch statements).
However, the pattern often consumes lots of time and space.


Marko

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


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

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


csiph-web