Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #66792 > unrolled thread
| Started by | Sam <lightaiyee@gmail.com> |
|---|---|
| First post | 2014-02-20 22:37 -0800 |
| Last post | 2014-03-01 15:22 +1100 |
| Articles | 20 on this page of 219 — 28 participants |
Back to article view | Back to comp.lang.python
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 10 of 11 — ← Prev page 1 … 8 9 [10] 11 Next page →
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-03-01 23:13 +0000 |
| Message-ID | <53126992$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #67333 |
On Sat, 01 Mar 2014 20:25:51 +0200, Marko Rauhamaa wrote:
> Steven D'Aprano <steve+comp.lang.python@pearwood.info>:
>
>> It seems to me that he's just assuming that symbols ought to be
>> singletons, hence his focus on identity rather than equality.
>
> Yes.
>
> A practical angle is this: if I used strings as symbols and compared
> them with "==", logically I shouldn't define them as constants
That doesn't follow. There is no logical connection between using named
constants (well, pseudo-constants, constants by convention only) and ==.
You can do both, or neither, or either one, whichever suits you.
You might as well say that when you have float constants:
TAU = 6.283185307179586
that "logically" implies that you are prohibited in asking whether
another float is less than or greater than TAU.
[...]
> The principal (practical) problem with that is that I might make a typo
> and write:
>
> if self.state == "IDLE ":
Then used named constants.
if self.state == IDLE:
See how easy it is? Just replace "is" with == unless you have a good
reason for caring about identity instead of equality.
--
Steven D'Aprano
http://import-that.dreamwidth.org/
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-03-02 00:03 +1100 |
| Message-ID | <mailman.7512.1393679028.18130.python-list@python.org> |
| In reply to | #67308 |
Marko Rauhamaa <marko@pacujo.net> writes: > Ben Finney <ben+python@benfinney.id.au>: > > > Use ‘==’, since that's all that matters for getting a value that will > > work fine. > > You are telling me to use '==' if I choose string objects and 'is' if I > choose some other objects. No. I'm telling you that ‘is’ is *wrong* for comparing strings, because it is unreliable. > I prefer a solution that works regardless of what objects I choose for > identifiers. Some languages have a “symbol” type, whose values can be directly compared. Python doesn't have such a type. If you want to use strings as a substitute, go ahead: they work fine. But compare strings by *equality*, not identity, because it's their *values* which will be the identifiers. Their object identity will not be reliably comparable. That's what everyone has been telling you all along, for reasons already explained. > There really is no taboo against string object identity if you know what > you are doing. You, as has been amply demonstrated, do not, despite your dogmatic assertions. -- \ “Under democracy one party always devotes its chief energies to | `\ trying to prove that the other party is unfit to rule — and | _o__) both commonly succeed, and are right.” —Henry L. Mencken | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-03-01 19:23 +0200 |
| Message-ID | <87r46l96j6.fsf@elektro.pacujo.net> |
| In reply to | #67314 |
Ben Finney <ben+python@benfinney.id.au>: > No. I'm telling you that ‘is’ is *wrong* for comparing strings, > because it is unreliable. No, it isn't as long as the string object references have a common assignment "pedigree." Assignment (including parameter passing) is guaranteed to preserve identity of any object. Marko
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-03-02 04:30 +1100 |
| Message-ID | <mailman.7519.1393695050.18130.python-list@python.org> |
| In reply to | #67323 |
On Sun, Mar 2, 2014 at 4:23 AM, Marko Rauhamaa <marko@pacujo.net> wrote: > Ben Finney <ben+python@benfinney.id.au>: > >> No. I'm telling you that ‘is’ is *wrong* for comparing strings, >> because it is unreliable. > > No, it isn't as long as the string object references have a common > assignment "pedigree." Assignment (including parameter passing) is > guaranteed to preserve identity of any object. Of course it is, but your identity tests also depend on there NOT being a common object when there is NOT an "assignment pedigree". The positive is guaranteed; the negative is not. And if you don't care about a false positive - that is, that some other string with the same value matches - then what you actually want is equality, not identity, comparison. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-03-02 09:34 +1100 |
| Message-ID | <mailman.7545.1393713311.18130.python-list@python.org> |
| In reply to | #67323 |
Marko Rauhamaa <marko@pacujo.net> writes: > Ben Finney <ben+python@benfinney.id.au>: > > > No. I'm telling you that ‘is’ is *wrong* for comparing strings, > > because it is unreliable. > > No, it isn't as long as the string object references have a common > assignment "pedigree." Assignment (including parameter passing) is > guaranteed to preserve identity of any object. The unreliability isn't “will the same object have the same identity?”. The unreliability is “will objects defined elsewhere have a different identity?” In the case of Python strings, the latter question is not reliably answerable from the programmer's perspective. You are obstinately ignoring the point that the identity of a string is *not* guaranteed to be different from a string with the same value. Since you're persistently misconstruing what is being said to you, I'm not going to run through it all again. -- \ “[W]e are still the first generation of users, and for all that | `\ we may have invented the net, we still don't really get it.” | _o__) —Douglas Adams | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-03-02 10:03 +0200 |
| Message-ID | <87zjl93u49.fsf@elektro.pacujo.net> |
| In reply to | #67385 |
Ben Finney <ben+python@benfinney.id.au>: > The unreliability is “will objects defined elsewhere have a different > identity?” That question is not interesting in my context, and has no bearing on the correctness of the program. Marko
[toc] | [prev] | [next] | [standalone]
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Date | 2014-03-02 21:59 +1100 |
| Message-ID | <mailman.7569.1393757980.18130.python-list@python.org> |
| In reply to | #67417 |
Marko Rauhamaa <marko@pacujo.net> writes: > Ben Finney <ben+python@benfinney.id.au>: > > > The unreliability is “will objects defined elsewhere have a different > > identity?” > > That question is not interesting in my context, and has no bearing on > the correctness of the program. You keep vacillating between two positions: pick one for the context. Either you care about object identity in this context, and the above observation is relevant. Or, you don't care about object identity in this context, and you should avoid ‘is’ and use ‘==’. But you cannot have both. -- \ “You know I could rent you out as a decoy for duck hunters?” | `\ —Groucho Marx | _o__) | Ben Finney
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-03-02 13:00 +0000 |
| Message-ID | <mailman.7574.1393765255.18130.python-list@python.org> |
| In reply to | #67417 |
On 02/03/2014 10:59, Ben Finney wrote: > Marko Rauhamaa <marko@pacujo.net> writes: > >> Ben Finney <ben+python@benfinney.id.au>: >> >>> The unreliability is “will objects defined elsewhere have a different >>> identity?” >> >> That question is not interesting in my context, and has no bearing on >> the correctness of the program. > > You keep vacillating between two positions: pick one for the context. > > Either you care about object identity in this context, and the above > observation is relevant. > > Or, you don't care about object identity in this context, and you should > avoid ‘is’ and use ‘==’. > > But you cannot have both. > Unless you're a troll. -- 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]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-03-01 15:15 +0000 |
| Message-ID | <mailman.7515.1393686907.18130.python-list@python.org> |
| In reply to | #67308 |
On 01/03/2014 11:59, Chris Angelico wrote: > On Sat, Mar 1, 2014 at 10:28 PM, Marko Rauhamaa <marko@pacujo.net> wrote: >> >> There really is no taboo against string object identity if you know what >> you are doing. > > And, as proven here in this thread, you do not know what you are doing. > Why do you think I admitted him onto my dream team some days ago? :) -- 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]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2014-03-01 10:05 -0700 |
| Message-ID | <mailman.7517.1393693559.18130.python-list@python.org> |
| In reply to | #67308 |
On 03/01/2014 04:28 AM, Marko Rauhamaa wrote:
> Ben Finney <ben+python@benfinney.id.au>:
>
>> Use ‘==’, since that's all that matters for getting a value that will
>> work fine.
>
> You are telling me to use '==' if I choose string objects and 'is' if I
> choose some other objects.
No, '==' works fine no matter what objects you assign to your state
variables.
class Foo(object):
STATE1 = object()
STATE2 = "testing"
STATE3 = 2
def __init__(self):
self.state = Foo.STATE1
def bar(self):
if self.state == Foo.STATE1:
pass
elif self.state == Foo.STATE2:
pass
elif self.state == Foo.STATE3:
pass
> I prefer a solution that works regardless of what objects I choose for
> identifiers.
As shown, '==' does work for this too. I don't know which is more
correct, but it does work.
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-03-01 19:29 +0200 |
| Message-ID | <87mwh9969m.fsf@elektro.pacujo.net> |
| In reply to | #67320 |
Michael Torrie <torriem@gmail.com>:
> No, '==' works fine no matter what objects you assign to your state
> variables.
Well, it doesn't since
>>> a = float("nan")
>>> a is a
True
>>> a == a
False
More generally, it depends on how the __eq__ method has been implemented
for the class. You might even (foolishly) define a class such that:
>>> a == b
False
>>> a != b
False
The "is" operator is immune to such modality.
Marko
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-03-02 04:36 +1100 |
| Message-ID | <mailman.7520.1393695397.18130.python-list@python.org> |
| In reply to | #67325 |
On Sun, Mar 2, 2014 at 4:29 AM, Marko Rauhamaa <marko@pacujo.net> wrote: > You might even (foolishly) define a class such that: > > >>> a == b > False > >>> a != b > False Not necessarily even foolish; the SQL NULL value [1] behaves like that. ChrisA [1] Which isn't a value, except when it is
[toc] | [prev] | [next] | [standalone]
| From | Michael Torrie <torriem@gmail.com> |
|---|---|
| Date | 2014-03-01 11:06 -0700 |
| Message-ID | <mailman.7522.1393697225.18130.python-list@python.org> |
| In reply to | #67325 |
On 03/01/2014 10:29 AM, Marko Rauhamaa wrote:
> Michael Torrie <torriem@gmail.com>:
>
>> No, '==' works fine no matter what objects you assign to your state
>> variables.
>
> Well, it doesn't since
>
> >>> a = float("nan")
> >>> a is a
> True
> >>> a == a
> False
>
> More generally, it depends on how the __eq__ method has been implemented
> for the class. You might even (foolishly) define a class such that:
>
> >>> a == b
> False
> >>> a != b
> False
Yes, good point.
[toc] | [prev] | [next] | [standalone]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2014-03-01 13:30 -0500 |
| Message-ID | <roy-E94637.13300601032014@news.panix.com> |
| In reply to | #67325 |
In article <87mwh9969m.fsf@elektro.pacujo.net>,
Marko Rauhamaa <marko@pacujo.net> wrote:
> Michael Torrie <torriem@gmail.com>:
>
> > No, '==' works fine no matter what objects you assign to your state
> > variables.
>
> Well, it doesn't since
>
> >>> a = float("nan")
> >>> a is a
> True
> >>> a == a
> False
>
> More generally, it depends on how the __eq__ method has been implemented
> for the class. You might even (foolishly) define a class such that:
>
> >>> a == b
> False
> >>> a != b
> False
Well, there's always things like SQL's NULL, which is both not equal and
not not equal to itself.
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-03-02 08:35 +0000 |
| Message-ID | <5312ed4b$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #67325 |
On Sat, 01 Mar 2014 19:29:41 +0200, Marko Rauhamaa wrote:
> Michael Torrie <torriem@gmail.com>:
>
>> No, '==' works fine no matter what objects you assign to your state
>> variables.
>
> Well, it doesn't since
>
> >>> a = float("nan")
> >>> a is a
> True
> >>> a == a
> False
No, that is working correctly, so the comment that equals works fine is
correct: returning False is the correct thing to do if one or both of the
objects are a NAN. NANs are supposed to compare unequal to everything,
including themselves.
The is operator and the == operator do not have the same purpose and they
do not do the same thing. "is" should not be considered an improved ==
without the quirks, this is not PHP and we're not comparing == and ===.
The argument here is not about which operator performs the check we want,
but over what check we want: do we want an identity test or an equality
test?
--
Steven D'Aprano
http://import-that.dreamwidth.org/
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-03-02 11:35 +0200 |
| Message-ID | <87ha7h9c40.fsf@elektro.pacujo.net> |
| In reply to | #67418 |
Steven D'Aprano <steve+comp.lang.python@pearwood.info>:
> On Sat, 01 Mar 2014 19:29:41 +0200, Marko Rauhamaa wrote:
>> Michael Torrie <torriem@gmail.com>:
>>> No, '==' works fine no matter what objects you assign to your state
>>> variables.
>>
>> Well, it doesn't since
>>
>> >>> a = float("nan")
>> >>> a is a
>> True
>> >>> a == a
>> False
>
> No, that is working correctly, so the comment that equals works fine
> is correct: returning False is the correct thing to do if one or both
> of the objects are a NAN. NANs are supposed to compare unequal to
> everything, including themselves.
Nobody is saying there's a bug in the implementation of "==". I'm just
saying "==" cannot be taken as a universal superset of "is". Therefore
a program cannot blindly use "==" to test for identity.
That's why "==" is a bit fishy. It immediately raises the question: what
does it mean for a == b, especially since the exact implementation of a
and b are intended to be opaque.
Example:
The os module defines the constants os.SEEK_SET, os.SEEK_CUR and
os.SEEK_END that can be used as arguments for os.lseek(). Must those
constants be used, or can a regular integer be used instead? The
documentation clearly states that integers can be used:
SEEK_SET or 0 to set the position relative to the beginning of the
file; SEEK_CUR or 1 to set it relative to the current position;
SEEK_END or 2 to set it relative to the end of the file.
However, on the same reference page, os.posix_fadvise() is defined. We
read:
advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,
POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or
POSIX_FADV_DONTNEED
and:
os.POSIX_FADV_NORMAL
os.POSIX_FADV_SEQUENTIAL
os.POSIX_FADV_RANDOM
os.POSIX_FADV_NOREUSE
os.POSIX_FADV_WILLNEED
os.POSIX_FADV_DONTNEED
Flags that can be used in advice in posix_fadvise()
Now, what kinds of object are those constants? We are not supposed to
know or care. We could peek into the implementation, but it would be a
grave mistake to trust the implementation choices in the application.
So in my application code I might set:
favd_flag = os.POSIX_FADV_RANDOM
in some other part of my code I might want to see how "flag" was set.
Should I use "==" or "is" to test it?
If I take the API documentation on its face value, I *must* use "==" for
os.SEEK*:
if seek_flag == os.SEEK_END:
...
and I *must* use "is" for os.POSIX_FAVD_*:
if fsavd_flag is os.POSIX_FADV_RANDOM:
...
Since, for all I know, os.POSIX_FAVD_RANDOM might return a random value
for __eq__().
Marko
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-03-02 11:40 +0200 |
| Message-ID | <87d2i59bwq.fsf@elektro.pacujo.net> |
| In reply to | #67419 |
Marko Rauhamaa <marko@pacujo.net>:
> If I take the API documentation on its face value, [...]
> I *must* use "is" for os.POSIX_FAVD_*:
>
> if fsavd_flag is os.POSIX_FADV_RANDOM:
> ...
However, since a documentation flaw is more than likely, it is even more
prudent to avoid both "==" and "is" and create a set of shadow constants
in the application code:
if self.fsavd_flag is self.FAVD_RANDOM:
os.posix_fadvice(fd, offset, len, os.POSIX_FAVD_RANDOM):
Marko
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-03-02 21:07 +1100 |
| Message-ID | <mailman.7567.1393754868.18130.python-list@python.org> |
| In reply to | #67419 |
On Sun, Mar 2, 2014 at 8:35 PM, Marko Rauhamaa <marko@pacujo.net> wrote: > However, on the same reference page, os.posix_fadvise() is defined. We > read: > > advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, > POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or > POSIX_FADV_DONTNEED > > Now, what kinds of object are those constants? We are not supposed to > know or care. We could peek into the implementation, but it would be a > grave mistake to trust the implementation choices in the application. > > So in my application code I might set: > > favd_flag = os.POSIX_FADV_RANDOM > > in some other part of my code I might want to see how "flag" was set. > Should I use "==" or "is" to test it? In the absence of any advice to the contrary, I would use == to test. The flags are most likely to be, in order: * An enumeration, in a sufficiently new Python * Integers * Strings * Arbitrary object()s All of the above will compare correctly with ==, and if someone stuffs in an object that compares equal to more than one of them, they're likely to have problems at the far end. If identity is really crucial, I would expect there to be a comment in the docs. And there's another thing you can do to test. >>> import os >>> type(os.POSIX_FADV_RANDOM) <class 'int'> So use ==. If it's later changed and you have to instead use 'is', you can change your code. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-03-02 12:37 +0200 |
| Message-ID | <8761nwanty.fsf@elektro.pacujo.net> |
| In reply to | #67422 |
Chris Angelico <rosuav@gmail.com>:
> And there's another thing you can do to test.
>
>>>> import os
>>>> type(os.POSIX_FADV_RANDOM)
> <class 'int'>
Is that what you do in your programs?
> So use ==. If it's later changed and you have to instead use 'is', you
> can change your code.
Quite a robust API, huh?
Anyway, you recognize that the API definer is within their rights to
require 'is' semantics for the constants. IOW, the application must use
the given constant objects and nothing that happens to be == to them.
Consequently, the implementer is within their rights to define:
def __eq__():
return True
Marko
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-03-02 10:44 +0000 |
| Message-ID | <53130b83$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #67419 |
On Sun, 02 Mar 2014 11:35:43 +0200, Marko Rauhamaa wrote: > Nobody is saying there's a bug in the implementation of "==". I'm just > saying "==" cannot be taken as a universal superset of "is". Therefore a > program cannot blindly use "==" to test for identity. Um, yes? Nor can you use ">" to test for identity, or "+", or "%", or any other operator other than "is". Why do you think it is a problem that == doesn't test for identity? It's not supposed to test for identity. Why do you want to test for identity? I think I've asked five times now, why you care whether a state value has one instance or a thousand instances, and you haven't even attempted an answer. > That's why "==" is a bit fishy. It immediately raises the question: what > does it mean for a == b, especially since the exact implementation of a > and b are intended to be opaque. It means that a equals b. For ints, it means that they have the same numeric value. The same applies for floats. For strings, it means that they contain the same code points in the same order. And so on. For all built-in types, equality is well-defined. For custom types you create yourself, the onus is on you to ensure that equality is meaningful and well-defined. > Example: > > The os module defines the constants os.SEEK_SET, os.SEEK_CUR and > os.SEEK_END that can be used as arguments for os.lseek(). Must those > constants be used, or can a regular integer be used instead? The > documentation clearly states that integers can be used: > > SEEK_SET or 0 to set the position relative to the beginning of the > file; SEEK_CUR or 1 to set it relative to the current position; > SEEK_END or 2 to set it relative to the end of the file. > > However, on the same reference page, os.posix_fadvise() is defined. We > read: > > advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL, > POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED or > POSIX_FADV_DONTNEED > > and: > > os.POSIX_FADV_NORMAL > os.POSIX_FADV_SEQUENTIAL > os.POSIX_FADV_RANDOM > os.POSIX_FADV_NOREUSE > os.POSIX_FADV_WILLNEED > os.POSIX_FADV_DONTNEED > > Flags that can be used in advice in posix_fadvise() > > Now, what kinds of object are those constants? We are not supposed to > know or care. Incorrect. We are supposed to know and care. os.posix is exactly the sort of library I mentioned earlier when I said sometimes you're constrained by compatibility with some other system. In this case, the os module is explicitly designed to be compatible with the POSIX interface, which is defined to use certain integer values as flags. This is not an implementation choice which implementers can change at will, it is part of the interface. The specific *values* possibly may be allowed to vary from platform to platform, and since this is C even the definition of "int" may be platform specific, but not that fact that they are ints. Hence the value of POSIX_FADV_RANDOM could, theoretically, be different under Linux and FreeBSD (say). It probably isn't, but it could be. If you hard-code the magic number 1 in your code, you're risking the (tiny) chance of it failing on some obscure POSIX system. But that doesn't imply that we must test for object identity. There could be a million different instances, all with the value POSIX_FADV_RANDOM. Python does not guarantee that there is only a single 1 instance. If you want to test whether a value is os.POSIX_FADV_RANDOM, the right way is to compare that value for equality with os.POSIX_FADV_RANDOM, not identity. > We could peek into the implementation, but it would be a > grave mistake to trust the implementation choices in the application. > So in my application code I might set: > > favd_flag = os.POSIX_FADV_RANDOM A much better choice than hard-coding the magic value 1. But that choice has absolutely nothing to do with whether 1 is a singleton or not. > in some other part of my code I might want to see how "flag" was set. > Should I use "==" or "is" to test it? Equals, of course. There is absolutely no question about that. To even *think* that you should test it with "is" means that you have completely misunderstood what you are doing here. Why are you relying on an implementation detail that CPython happens to cache and reuse small integers like 1? What happens if you run your code under an implementation of Python that doesn't cache small ints? Or if your platform happens to set POSIX_FADV_RANDOM to a non-cached value like 8531201? Python does not promise that POSIX_FADV_RANDOM will be a singleton value. Using "is" is unsafe. > If I take the API documentation on its face value, I *must* use "==" for > os.SEEK*: Correct. > if seek_flag == os.SEEK_END: > ... > > and I *must* use "is" for os.POSIX_FAVD_*: Incorrect. > if fsavd_flag is os.POSIX_FADV_RANDOM: > ... > > Since, for all I know, os.POSIX_FAVD_RANDOM might return a random value > for __eq__(). For all *you* know, perhaps, but since os.posix_fadvise is a thin wrapper around the POSIX C function fadvise, and that is documented as expecting ints for the advice parameter, that cannot be the case. Unfortunately Python has not had the money put into it to make it an ISO standard like Java, and so there are certain areas where the behaviour is known by common practice but not officially documented. (A bit like British common law.) That the os module is a thin wrapper around os- specific services may not be explicitly stated, but it is nevertheless true. -- Steven D'Aprano http://import-that.dreamwidth.org/
[toc] | [prev] | [next] | [standalone]
Page 10 of 11 — ← Prev page 1 … 8 9 [10] 11 Next page →
Back to top | Article view | comp.lang.python
csiph-web