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 1 of 11 [1] 2 3 … 11 Next page →
| From | Sam <lightaiyee@gmail.com> |
|---|---|
| Date | 2014-02-20 22:37 -0800 |
| Subject | Can global variable be passed into Python function? |
| Message-ID | <27ac2248-0ca3-4ba6-9d25-eaad324bc5e9@googlegroups.com> |
I need to pass a global variable into a python function. However, the global variable does not seem to be assigned after the function ends. Is it because parameters are not passed by reference? How can I get function parameters to be passed by reference in Python?
[toc] | [next] | [standalone]
| From | dieter <dieter@handshake.de> |
|---|---|
| Date | 2014-02-21 08:23 +0100 |
| Message-ID | <mailman.7214.1392967413.18130.python-list@python.org> |
| In reply to | #66792 |
Sam <lightaiyee@gmail.com> writes:
> I need to pass a global variable into a python function.
Python does not really have the concept "variable".
What appears to be a variable is in fact only the binding of an
object to a name. If you assign something to a variable,
all you do is binding a different object to the name.
Thus, if you have:
i = 1
def f(x): x = 5
f(i)
Then "i" will remain "1" and not become "5".
The effect of "x = 5" is that the name "x" gets bound to "5"
(where is formerly was bound to "1").
>However, the global variable does not seem to be assigned after the function ends. Is it because parameters are not passed by reference?
Python lacks the notion of "variable". Thus, it does not
pass variables into functions but objects.
The objects, however, get passed by reference.
>How can I get function parameters to be passed by reference in Python?
You can implement your own concept of variable, e.g. like this:
class Variable(object):
def __init__(self, value): self.value = value
The little program above then becomes:
i = Variable(1)
def f(x): x.value = 5
f(i)
i.value # this is now 5
[toc] | [prev] | [next] | [standalone]
| From | Jussi Piitulainen <jpiitula@ling.helsinki.fi> |
|---|---|
| Date | 2014-02-21 10:55 +0200 |
| Message-ID | <qotfvnc26bd.fsf@ruuvi.it.helsinki.fi> |
| In reply to | #66807 |
dieter writes:
> Sam writes:
>
> > I need to pass a global variable into a python function.
>
> Python does not really have the concept "variable".
>
> What appears to be a variable is in fact only the binding of an
> object to a name. If you assign something to a variable,
> all you do is binding a different object to the name.
>
> Thus, if you have:
>
> i = 1
> def f(x): x = 5
>
> f(i)
>
> Then "i" will remain "1" and not become "5".
> The effect of "x = 5" is that the name "x" gets bound to "5"
> (where is formerly was bound to "1").
In alleged contrast, the observable behaviour of languages that "have
variables" is the same. This is not considered confusing by the people
who insist that there are no variables in Python.
Note: I do not object to Python's choice of different preferred
terminology. Python seems to be doing fine with that. I do object to
the insistence that Python needs this different terminology because it
behaves differently from the languages where variables are called
variables. Python behaves the same.
Here's Java, where I demonstrate with both a class variable i and a
local variable j; I used String so that this same demonstration will
still serve after someone points out that Java's primite numbers are
not quite objects, which is true but irrelevant:
$ cat Var.java
public class Var {
public static String i = "1";
public static String f(String x) {
x = "5";
return x;
}
public static void main(String... args) {
String j = "2";
System.out.println("i == " + i + ", j == " + j);
System.out.println("f(i) == " + f(i) + ", " +
"f(j) == " + f(j));
System.out.println("i == " + i + ", j == " + j);
}
}
$ javac Var.java
$ java -cp . Var
i == 1, j == 2
f(i) == 5, f(j) == 5
i == 1, j == 2
$
This is C, where I again demonstrate with both a global and a local
variable, but here I leave them as ints; I think C might be a language
where the word "variable" has been used to mean something like a block
of memory, which is a different usage; still, would someone be willing
to explain the behaviour of this program by "C lacks variables":
$ cat var.c
#include <stdio.h>
int i = 1;
int f(int x) { x = 5; return x; }
main() {
int j = 2;
printf("i == %d, j == %d\n", i, j);
printf("f(i) == %d, f(j) == %d\n", f(i), f(j));
printf("i == %d, j == %d\n", i, j);
}
$ gcc -o var var.c
$ ./var
i == 1, j == 2
f(i) == 5, f(j) == 5
i == 1, j == 2
$
This is Scheme, which is where I come from; its variables behave the
same as the corresponding machinery in Python with regard to the
problem at hand:
$ cat var.scm
(define i 1)
(define (f x) (set! x 5) x)
(let ((j 2))
(display "i == ") (write i) (display ", j == ") (write j) (newline)
(display "f(i) == ") (write (f i))
(display ", f(j) == ") (write (f j)) (newline)
(display "i == ") (write i) (display ", j == ") (write j) (newline))
$ gsi var.scm
i == 1, j == 2
f(i) == 5, f(j) == 5
i == 1, j == 2
$
> > However, the global variable does not seem to be assigned after
> > the function ends. Is it because parameters are not passed by
> > reference?
>
> Python lacks the notion of "variable". Thus, it does not
> pass variables into functions but objects.
> The objects, however, get passed by reference.
I think the relevant answer is simply that i and x are different
variables. In Python terminology, I think you would have to say that
they are different names. With a slight change, you would need to
explain how i and i are different names (I think), and then you would
introduce the concept of different namespaces.
Python indeed does not pass variables (and this is a relevant), but
neither do the other languages that "have variables".
[snip]
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-02-21 12:10 +0200 |
| Message-ID | <87fvnc6aj3.fsf@elektro.pacujo.net> |
| In reply to | #66816 |
Jussi Piitulainen <jpiitula@ling.helsinki.fi>:
> In alleged contrast, the observable behaviour of languages that "have
> variables" is the same. This is not considered confusing by the people
> who insist that there are no variables in Python.
But of course there are variables in Python:
By “frozen” we mean that all local state is retained, including the
current bindings of local variables, [...] (<URL:
http://docs.python.org/3.2/reference/simple_stmts.html
#the-yield-statement>)
The public names defined by a module are determined by checking the
module’s namespace for a variable named __all__ (<URL:
http://docs.python.org/3.2/reference/simple_stmts.html
#the-import-statement>)
It would be impossible to assign to a global variable without global
(<URL: http://docs.python.org/3.2/reference/simple_stmts.html
#the-global-statement>)
etc etc.
However, your point about "observable behavior" is key, and Python users
of all people should get the principle (as it is related to duck
typing).
> Python indeed does not pass variables (and this is a relevant), but
> neither do the other languages that "have variables".
Maybe the idea comes from the fact that you can't easily pass a
variable to a function for modification.
Consider this C function:
void make_printable(const char **ref)
{
if (!*ref)
*ref = "<NULL>";
}
which allows:
make_printable(&x);
make_printable(&s->name);
make_printable(&a[i]);
Marko
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2014-02-21 08:34 +0100 |
| Message-ID | <mailman.7215.1392968086.18130.python-list@python.org> |
| In reply to | #66792 |
Sam wrote:
> I need to pass a global variable into a python function. However, the
> global variable does not seem to be assigned after the function ends. Is
> it because parameters are not passed by reference? How can I get function
> parameters to be passed by reference in Python?
If the variable you want to process is always the same global variable you
can declare it:
>>> x = 0
>>> def inc_x():
... global x
... x += 1
...
>>> x
0
>>> inc_x()
>>> x
1
>>> inc_x(); inc_x()
>>> x
3
If you want to change ("rebind") varying global names you have to be
explicit:
>>> def inc(x):
... return x + 1
...
>>> x = 0
>>> x = inc(x)
>>> y = 0
>>> y = inc(y)
>>> y = inc(y)
>>> x, y
(1, 2)
Then there are ugly hacks that make your code hard to follow. Don't use
these:
>>> def inc(name):
... globals()[name] += 1
...
>>> inc("x")
>>> inc("x")
>>> x
3
>>> def inc(module, name):
... setattr(module, name, getattr(module, name) + 1)
...
>>> import __main__
>>> inc(__main__, "x")
>>> inc(__main__, "x")
>>> inc(__main__, "x")
>>> x
6
[toc] | [prev] | [next] | [standalone]
| From | Gary Herron <gary.herron@islandtraining.com> |
|---|---|
| Date | 2014-02-21 00:41 -0800 |
| Message-ID | <mailman.7221.1392972122.18130.python-list@python.org> |
| In reply to | #66792 |
On 02/20/2014 10:37 PM, Sam wrote:
> I need to pass a global variable into a python function. However, the global variable does not seem to be assigned after the function ends. Is it because parameters are not passed by reference? How can I get function parameters to be passed by reference in Python?
Are you passing a value *into* a function, or back *out of* the
function? These are two very different things, and your question
mentions both and seems to confuse them.
You can pass any value into a function through its parameters, whether
that value comes from a local variable, global variable, or the result
of some computation. (But consider: it is the value that is being passed
in -- not the variable that contains that value.) You can't pass values
back out from a function through assignment to any of the parameters.
The global statement is a way to allow a function to assign to a global
variable, but this would not be considered "passing" a global into a
function. It's just a way to access and assign to a global variable
from withing a function.
v = 123
def f(...):
global v # Now v refers to the global v
print(v) # Accesses and prints the global v
v = 456 # Assigns to the global v.
Gary Herron
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-02-21 08:55 +0000 |
| Message-ID | <53071470$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #66792 |
On Thu, 20 Feb 2014 22:37:59 -0800, Sam wrote: > I need to pass a global variable into a python function. However, the > global variable does not seem to be assigned after the function ends. Is > it because parameters are not passed by reference? How can I get > function parameters to be passed by reference in Python? You cannot. Python does not support either pass-by-reference or pass-by- value calling conventions. Instead, it supports the same calling convention as Java, Ruby and other modern languages (which confusingly those two languages both call something different), "call by object sharing". To understand more about Python's calling convention, and why neither call-by-reference nor call-by-value are appropriate, please read these articles: https://mail.python.org/pipermail/tutor/2010-December/080505.html http://effbot.org/zone/call-by-object.htm and also see the Wikipedia article: http://en.wikipedia.org/wiki/Evaluation_strategy If you show us a sample of your code, together of a sample of how you expect it to work, we can suggest an alternate way to solve that problem. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-02-21 07:13 -0500 |
| Message-ID | <mailman.7226.1392984818.18130.python-list@python.org> |
| In reply to | #66792 |
On 2/21/14 2:23 AM, dieter wrote: > Sam<lightaiyee@gmail.com> writes: > >> >I need to pass a global variable into a python function. > Python does not really have the concept "variable". > > What appears to be a variable is in fact only the binding of an > object to a name. If you assign something to a variable, > all you do is binding a different object to the name. > Man, do I hate this idea that Python has no variables. It has variables (names associated with values, and the values can change over the course of the program), they just don't work the same as C or Fortran variables. In fact, they work exactly the same as Javascript or Ruby variables. Python's variables are names bound to values. http://nedbatchelder.com/text/names.html has lots more details. -- Ned Batchelder, http://nedbatchelder.com
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-02-21 14:52 +0200 |
| Message-ID | <87ppmgeig2.fsf@elektro.pacujo.net> |
| In reply to | #66829 |
Ned Batchelder <ned@nedbatchelder.com>: > Man, do I hate this idea that Python has no variables. It has > variables (names associated with values, and the values can change > over the course of the program), In classic functional programming, the values of variables can't change but they are still called variables (even though "parameters" might be more fitting). > they just don't work the same as C or Fortran variables. In fact, they > work exactly the same as Javascript or Ruby variables. Apart from a fact that a C variable has an address (references are first-class objects, if you will), I really don't see a difference between a C variable and a Python variable. Marko
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-02-22 03:28 +0000 |
| Message-ID | <5308194f$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #66829 |
On Fri, 21 Feb 2014 07:13:25 -0500, Ned Batchelder wrote: > On 2/21/14 2:23 AM, dieter wrote: >> Sam<lightaiyee@gmail.com> writes: >> >>> >I need to pass a global variable into a python function. >> Python does not really have the concept "variable". >> >> What appears to be a variable is in fact only the binding of an object >> to a name. If you assign something to a variable, all you do is binding >> a different object to the name. >> >> > Man, do I hate this idea that Python has no variables. It has variables > (names associated with values, and the values can change over the course > of the program), they just don't work the same as C or Fortran > variables. In fact, they work exactly the same as Javascript or Ruby > variables. I sympathise with your view. It seems quite ridiculous to claim that Python has no variables. If it has no variables, what on earth does it mean when we say "x = 42"? But the very ridiculousness is what gives it the attention-grabbing power that makes it a useful meme. "Python variables don't behave like C variables" might be true, but it's also wish-washy and forgettable. In my own case, I never quite got Python's name binding semantics until I was introduced to the "Python has no variables" meme. That got my attention long enough to listen to the actual message: my assumptions about how variables behave was based on Pascal semantics, and Python doesn't quite follow the same rules. Consequently, if I implicitly define "variable" to mean "Pascal variables", as I had been, then Python has no variables, it has these things called "name bindings". That's when I got it. I went through a phase where I too insisted that Python had no variables. But then my natural laziness asserted itself, and I decided that the word "variable" is too useful to always reject it (and besides, C- and Pascal- like languages don't have a monopoly on the word "variable"). Now, I use the terms "variable" or "reference" or "name binding" as I feel makes the most sense in context, depending on my best guess of the risk of misunderstanding or confusion. -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Ned Batchelder <ned@nedbatchelder.com> |
|---|---|
| Date | 2014-02-21 22:45 -0500 |
| Message-ID | <mailman.7249.1393040726.18130.python-list@python.org> |
| In reply to | #66869 |
On 2/21/14 10:28 PM, Steven D'Aprano wrote: > On Fri, 21 Feb 2014 07:13:25 -0500, Ned Batchelder wrote: > >> On 2/21/14 2:23 AM, dieter wrote: >>> Sam<lightaiyee@gmail.com> writes: >>> >>>>> I need to pass a global variable into a python function. >>> Python does not really have the concept "variable". >>> >>> What appears to be a variable is in fact only the binding of an object >>> to a name. If you assign something to a variable, all you do is binding >>> a different object to the name. >>> >>> >> Man, do I hate this idea that Python has no variables. It has variables >> (names associated with values, and the values can change over the course >> of the program), they just don't work the same as C or Fortran >> variables. In fact, they work exactly the same as Javascript or Ruby >> variables. > > I sympathise with your view. It seems quite ridiculous to claim that > Python has no variables. If it has no variables, what on earth does it > mean when we say "x = 42"? > > But the very ridiculousness is what gives it the attention-grabbing power > that makes it a useful meme. "Python variables don't behave like C > variables" might be true, but it's also wish-washy and forgettable. > > In my own case, I never quite got Python's name binding semantics until I > was introduced to the "Python has no variables" meme. That got my > attention long enough to listen to the actual message: my assumptions > about how variables behave was based on Pascal semantics, and Python > doesn't quite follow the same rules. Consequently, if I implicitly define > "variable" to mean "Pascal variables", as I had been, then Python has no > variables, it has these things called "name bindings". > > That's when I got it. > > I went through a phase where I too insisted that Python had no variables. > But then my natural laziness asserted itself, and I decided that the word > "variable" is too useful to always reject it (and besides, C- and Pascal- > like languages don't have a monopoly on the word "variable"). Now, I use > the terms "variable" or "reference" or "name binding" as I feel makes the > most sense in context, depending on my best guess of the risk of > misunderstanding or confusion. > > This is an interesting perspective, thanks. I think it might be that the OP's question, "Can a global variable be passed into a function", really had nothing to do with the name/value/variable distinction, and we've done it again: taken a simple question and spun off into pedantry and trivia. -- Ned Batchelder, http://nedbatchelder.com
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-02-22 06:29 +0000 |
| Message-ID | <530843e6$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #66871 |
On Fri, 21 Feb 2014 22:45:14 -0500, Ned Batchelder wrote: > I think it might be that the OP's question, "Can a global variable be > passed into a function", really had nothing to do with the > name/value/variable distinction, and we've done it again: taken a simple > question and spun off into pedantry and trivia. You might be right, but the OP's question isn't really clear. Surely he didn't mean something as trivial as this? x = 1 # This is a global some_function(x) # Passing a global into a function His description, especially the comment about pass by reference, suggests that there is more to it than just passing a global variable as argument to a function. I think he is trying to *write* to the variable as well, as an output variable, something like this: x = 1 y = 2 some_function(x) assert x == 99 some_function(y) assert y == 99 Sadly, it appears to have been a drive-by question: Sam tossed a question out the window as he drove by, and may never come back for the answer... I hope I'm wrong, but it's been nearly 24 hours since the question was asked and not a peep from the OP. Sam, if you're out there reading this, please respond with more detail about what you are trying to do! -- Steven
[toc] | [prev] | [next] | [standalone]
| From | Travis Griggs <travisgriggs@gmail.com> |
|---|---|
| Date | 2014-02-21 09:59 -0800 |
| Message-ID | <mailman.7232.1393005565.18130.python-list@python.org> |
| In reply to | #66792 |
On Feb 21, 2014, at 4:13 AM, Ned Batchelder <ned@nedbatchelder.com> wrote: > Man, do I hate this idea that Python has no variables. It has variables (names associated with values, and the values can change over the course of the program), they just don't work the same as C or Fortran variables. In fact, they work exactly the same as Javascript or Ruby variables. Thank you! +11 I get tired of the “Python doesn’t have variables” line. What makes Python variables/bindings/references/aliases/namedvalues/slots/bucketsofstuff surprising to new arrivals from other language kingdoms, is that accessing is pragmatically implicit (walks the scope tree for you) and assignment may require explicitness. IOW, for some “variables”, you have to do something explicit to make the variable you want to refer to, vary. Some might say there is a lack of symmetry. Pros and cons. Personally, I don’t care. It’s one of those lessons you just learn as you go.
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-02-22 05:16 +1100 |
| Message-ID | <mailman.7234.1393006629.18130.python-list@python.org> |
| In reply to | #66792 |
On Sat, Feb 22, 2014 at 4:59 AM, Travis Griggs <travisgriggs@gmail.com> wrote:
> What makes Python variables/bindings/references/aliases/namedvalues/slots/bucketsofstuff surprising to new arrivals from other language kingdoms, is that accessing is pragmatically implicit (walks the scope tree for you) and assignment may require explicitness. IOW, for some “variables”, you have to do something explicit to make the variable you want to refer to, vary. Some might say there is a lack of symmetry. Pros and cons.
>
What you're looking at there, I think, is actually quite tangential to
the question of Python having/not having variables, and it's to do
with scoping rules. Correct me if I'm wrong.
g = "global"
c = 0
def f():
print(g) # References two globals
l = "local"
print(l) # References one global and one local
global c
c = 1 # References one global
As an alternative, Python could have asked us to declare the other way:
def f():
print(g) # References two globals
local l
l = "local"
print(l) # References one global and one local
c = 1 # References one global
It would still be the same name binding / object reference model, with
just a different keyword used to change the default behaviour of name
lookups. And the difference is comparatively slight. We get an
encouragement to use locals rather than globals, but on the flip side,
we need two keywords (global/nonlocal) where a single one (local, or
as ECMAScript puts it, "var") could handle the other case. It's a lack
of symmetry, but having worked with PHP (where you have to declare
*every* global, except for the magical superglobals, and except for
functions (which are in a completely different namespace), and except
for constants), I am very much glad that Python puts everything in
together as just "names", and then allows us to reference global names
like "print" without declarations. It's a miswart.
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Marko Rauhamaa <marko@pacujo.net> |
|---|---|
| Date | 2014-02-21 21:20 +0200 |
| Message-ID | <87bny0w9w3.fsf@elektro.pacujo.net> |
| In reply to | #66839 |
On the question of how variables can be passed to functions, C, of
course, has the & operator and Pascal has the "var" keyword.
An analogous thing can be achieved in Python 3 (but not in Python 2, I'm
afraid). The & operator corresponds to an ad hoc property class as in
the program below (not intended to be serious).
The program demonstrates how to write a universal "swap" function that
interchanges two references.
Marko
==clip=clip=clip========================================================
#!/usr/bin/env python3
import sys
def main():
some_list = [ 'a', 'b', 'c' ]
some_dict = { 'few' : 'ding',
'good' : 'dang',
'men' : 'dong' }
some_value = 'certainly'
class SomeListElementProperty:
"""&some_list[1]"""
def get(self):
return some_list[1]
def set(self, value):
some_list[1] = value
class SomeDictEntryProperty:
"""&some_dict["men"]"""
def get(self):
return some_dict['men']
def set(self, value):
some_dict['men'] = value
class SomeValueProperty:
"""&some_value"""
def get(self):
return some_value
def set(self, value):
nonlocal some_value
some_value = value
swap(SomeListElementProperty(), SomeDictEntryProperty())
swap(SomeListElementProperty(), SomeValueProperty())
sys.stdout.write("{}\n".format(some_list))
sys.stdout.write("{}\n".format(some_dict))
sys.stdout.write("{}\n".format(some_value))
def swap(px, py):
x = px.get()
y = py.get()
px.set(y)
py.set(x)
if __name__ == '__main__':
main()
==clip=clip=clip========================================================
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-02-22 17:36 +1100 |
| Message-ID | <mailman.7253.1393051016.18130.python-list@python.org> |
| In reply to | #66842 |
On Sat, Feb 22, 2014 at 6:20 AM, Marko Rauhamaa <marko@pacujo.net> wrote: > On the question of how variables can be passed to functions, C, of > course, has the & operator and Pascal has the "var" keyword. That doesn't pass a variable into a function, though. It passes the address of that variable, and C lets you stuff something into an address. That's not the same thing. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2014-02-22 07:18 +0000 |
| Message-ID | <53084f42$0$29985$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #66876 |
On Sat, 22 Feb 2014 17:36:52 +1100, Chris Angelico wrote:
> On Sat, Feb 22, 2014 at 6:20 AM, Marko Rauhamaa <marko@pacujo.net>
> wrote:
>> On the question of how variables can be passed to functions, C, of
>> course, has the & operator and Pascal has the "var" keyword.
>
> That doesn't pass a variable into a function, though. It passes the
> address of that variable, and C lets you stuff something into an
> address. That's not the same thing.
Be careful about conflating the implementation with the interface. As I
understand it, the interface C literally is that &x gives you the address
of x. But that's not what the var keyword is for in Pascal (although that
may be how it is implemented).
In Pascal, if you have a function or procedure:
procedure plus(a:integer, var b:integer);
begin
b := a+b;
end;
and a couple of variables in some other scope, for simplicity lets make
them global:
var
foo: int;
bar: int;
begin
foo := 23;
bar := 1;
plus(bar, foo);
writeln(foo);
end.
the output will be 24. If we could peek into procedure plus, we would see
that argument a was a *copy* of global bar, while argument b wasn't
merely a copy of foo, it actually was foo. So assigning to b inside plus
is the same as assigning to foo in the global scope.
If we added a call:
plus(2, bar);
to the main program, then inside plus argument a would have the value 2,
and argument b would now be precisely the same variable as global bar.
After the procedure returns, bar would have the value 3.
Now I daresay that under the hood, Pascal is passing the address of foo
(or bar) to the procedure plus, but inside plus you don't see that
address as the value of b. You see the value of foo (or bar).
C does not do that -- you have to manually manage the pointers yourself,
while Pascal does it for you. And Python also has nothing like that.
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-02-22 18:29 +1100 |
| Message-ID | <mailman.7254.1393054151.18130.python-list@python.org> |
| In reply to | #66878 |
On Sat, Feb 22, 2014 at 6:18 PM, Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote: > Now I daresay that under the hood, Pascal is passing the address of foo > (or bar) to the procedure plus, but inside plus you don't see that > address as the value of b. You see the value of foo (or bar). > > C does not do that -- you have to manually manage the pointers yourself, > while Pascal does it for you. And Python also has nothing like that. Yep. I should have clarified that I wasn't talking about Pascal; I'm not fluent in the language (last time I did anything at all with Pascal was probably about ten years ago, and not much then). In C, it strictly does what I said: & takes the address of something, * dereferences an address. There's no way to "pass a variable" - you have to pass the address, and that has consequences if, for instance, you *return* an address and the variable ceases to exist. (Does Pascal have an equivalent of that?) And Python has no such concept, anywhere. But anything that you can achieve in C using pointers, you can probably achieve in Python using more complex objects. ChrisA
[toc] | [prev] | [next] | [standalone]
| From | wxjmfauth@gmail.com |
|---|---|
| Date | 2014-02-22 00:02 -0800 |
| Message-ID | <585851dd-6106-4bc0-a7a2-8679aaa6ea29@googlegroups.com> |
| In reply to | #66880 |
>>> # a swapping variant >>> def swap(a, b): ... ab = [a, b] ... ab[1], ab[0] = ab[0], ab[1] ... return ab[0], ab[1] ... >>> a = 111 >>> id(a) 505627864 >>> b = 999 >>> id(b) 58278640 >>> a, b = swap(a, b) >>> a, id(a) (999, 58278640) >>> b, id(b) (111, 505627864) jmf
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2014-02-22 19:10 +1100 |
| Message-ID | <mailman.7255.1393056605.18130.python-list@python.org> |
| In reply to | #66881 |
On Sat, Feb 22, 2014 at 7:02 PM, <wxjmfauth@gmail.com> wrote:
>>>> # a swapping variant
>>>> def swap(a, b):
> ... ab = [a, b]
> ... ab[1], ab[0] = ab[0], ab[1]
> ... return ab[0], ab[1]
Provably identical to:
def swap(a, b):
return b, a
The rest is just fluff.
ChrisA
[toc] | [prev] | [next] | [standalone]
Page 1 of 11 [1] 2 3 … 11 Next page →
Back to top | Article view | comp.lang.python
csiph-web