Re: Pass by reference

2009-01-02 Thread alex goretoy
You are correct, terminology is a must. In order to stay on the same page. And yes, it;s not technically by ref. but it works for me at the moment. I was doing this in my code: l={"user":"asdf","pass":"goog"} d= { "login_url":"http://example.com/login";, "user":l["user"], "pass":l["pas

Re: Pass by reference

2009-01-02 Thread alex goretoy
You are correct, terminology is a must. In order to stay on the same page. And yes, it;s not technically by ref. but it works for me at the moment. I was doing this in my code: l={"user":"asdf","pass":"goog"} d= { "login_url":"http://example.com/login";, "user":l["user"], "pass":l["pas

Re: Pass by reference

2009-01-01 Thread Terry Reedy
alex goretoy wrote: I recently conquered this pass by ref thing. This is how I did it. What you did was to pass a mutable object and mutate it. Absolutely standard practice in Python. I am glad you learned it, but also learning and using the standard terminology will also help. Hope you e

Re: Pass by reference

2009-01-01 Thread alex goretoy
I recently conquered this pass by ref thing. This is how I did it. Python 2.4.3 (#1, Apr 3 2006, 14:02:53) [GCC 3.4.6] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> def f1(v): ... v="asdf" ... >>> def f2(v): ... v=["asdf"] ... >>> def f3(v): ...

Re: Pass by reference

2008-12-31 Thread Aaron Brady
On Dec 31, 5:30 am, iu2 wrote: > Hi, > > Is it possible somehow to change a varible by passing it to a > function? > > I tried this: > > def change_var(dict0, varname, val): >   dict0[varname] = val > > def test(): >   a = 100 >   change_var(locals(), 'a', 3) >   print a > > But test() didn't work

Re: Pass by reference

2008-12-31 Thread Chris Rebert
On Wed, Dec 31, 2008 at 5:04 AM, iu2 wrote: > For the 2 targets I have the variables comm1 and comm2. They are of > some class I wrote, representing many properties of the communication, > including the IP address. > There is one function that sends data, and it receives a commX var > (comm1 or c

Re: Pass by reference

2008-12-31 Thread iu2
On Dec 31, 1:48 pm, "Chris Rebert" wrote: ... > > Not really, or at the very least it'll be kludgey. Python uses > call-by-object (http://effbot.org/zone/call-by-object.htm), not > call-by-value or call-by-reference. > > Could you explain why you have to set so many variables to the same > value (

Re: Pass by reference

2008-12-31 Thread Bruno Desthuilliers
iu2 a écrit : Hi, Is it possible somehow to change a varible by passing it to a function? For which definition of "change a variable" ? I tried this: def change_var(dict0, varname, val): dict0[varname] = val Ok, this is mutating dict0, so it works. def test(): a = 100 change_var(

Re: Pass by reference

2008-12-31 Thread Chris Rebert
On Wed, Dec 31, 2008 at 3:30 AM, iu2 wrote: > Hi, > > Is it possible somehow to change a varible by passing it to a > function? > > I tried this: > > def change_var(dict0, varname, val): > dict0[varname] = val > > > def test(): > a = 100 > change_var(locals(), 'a', 3) > print a > > > But test(

Pass by reference

2008-12-31 Thread iu2
Hi, Is it possible somehow to change a varible by passing it to a function? I tried this: def change_var(dict0, varname, val): dict0[varname] = val def test(): a = 100 change_var(locals(), 'a', 3) print a But test() didn't work, the value a remains 100. I have several variables init

Re: Pass by reference or by value?

2007-08-16 Thread Steve Holden
Thomas Jollans wrote: > On Thursday 16 August 2007, Robert Dailey wrote: >> Hi, >> >> I previously created a topic named "Pass by reference or by value" where I >> inquired on how python's function parameters work. I received a lot of nice >> re

Re: Pass by reference or by value?

2007-08-16 Thread Steve Holden
Robert Dailey wrote: [but he top-posted, so he should consider himself smacked on the wrist] > On 8/16/07, *Steve Holden* <[EMAIL PROTECTED] > > wrote: > > Robert Dailey wrote: > > So immutable objects cannot be modified directly? I guess this means > > int

Re: Pass by reference or by value?

2007-08-16 Thread Thomas Jollans
On Thursday 16 August 2007, Robert Dailey wrote: > Hi, > > I previously created a topic named "Pass by reference or by value" where I > inquired on how python's function parameters work. I received a lot of nice > responses, however I'm still confused on the

Re: Pass by reference or by value?

2007-08-16 Thread Robert Dailey
Thanks Steve for your explanation. It was very helpful. I think I understand it now. By the way, by the .set method I meant: class Integer: def __init__( self, number=0 ): self._int = number def set( self, number ): self._int = number # later on mutableInt = Integer(

Re: Pass by reference or by value?

2007-08-16 Thread Steve Holden
Robert Dailey wrote: > So immutable objects cannot be modified directly? I guess this means > integers are immutable and the act of assigning to one is a completely > new definition? Correct. A new value is bound to the name or item on the left-hand side - remember, all variables are pointers

Re: Pass by reference or by value?

2007-08-16 Thread Robert Dailey
an object of type class Integer would allow me to modify the value from inside the function? On 8/16/07, Steve Holden <[EMAIL PROTECTED]> wrote: > > Robert Dailey wrote: > > Hi, > > > > I previously created a topic named "Pass by reference or by value" where

Re: Pass by reference or by value?

2007-08-16 Thread Steve Holden
Robert Dailey wrote: > Hi, > > I previously created a topic named "Pass by reference or by value" where > I inquired on how python's function parameters work. I received a lot of > nice responses, however I'm still confused on the topic. Note that I > co

Pass by reference or by value?

2007-08-16 Thread Robert Dailey
Hi, I previously created a topic named "Pass by reference or by value" where I inquired on how python's function parameters work. I received a lot of nice responses, however I'm still confused on the topic. Note that I come from a C++ background to Python, so any comparisons

Re: Pass by reference or by value?

2007-07-16 Thread Steve Holden
ts, as long as the variables passed as arguments were updated > in the caller. Early implementations of Fortran 90 often made copies > of array arguments, hurting performance. Current compilers do this > less often. > > It is common to pass constants and expressions to Fortran

Re: Pass by reference or by value?

2007-07-16 Thread Beliavsky
n made copies of array arguments, hurting performance. Current compilers do this less often. It is common to pass constants and expressions to Fortran procedures, which does not fit the pass-by-reference paradigm. Fortran 2003 has the VALUE attribute to give the C pass-by-value behavior when desired. -- http://mail.python.org/mailman/listinfo/python-list

Re: Pass by reference or by value?

2007-07-16 Thread John DeRosa
On 15 Jul 2007 16:07:43 -0700, [EMAIL PROTECTED] (Aahz) wrote: >[posted and e-mailed] > >[top-posting because I want to make only a one-line response] > >Please stick this on a web-page somewhere -- it makes an excellent >counterpoint to > >http://starship.python.net/crew/mwh/hacks/objectthink.htm

Re: Pass by reference or by value?

2007-07-15 Thread Aahz
t;> function, the value of the variable externally from the function is >> also modified. > > >Pass-by-value and pass-by-reference usually refer to the semantics >used in C and Fortran, respectively. > > >Here is an example showing the distinction between the 'pass-by-value&

Re: Pass by reference or by value?

2007-07-13 Thread sturlamolden
odified. Pass-by-value and pass-by-reference usually refer to the semantics used in C and Fortran, respectively. Here is an example showing the distinction between the 'pass-by-value' semantics of C and the 'pass-by-reference' semantics of Fortran: In C you can pass poi

Re: Pass by reference or by value?

2007-07-13 Thread Dan Bishop
On Jul 13, 2:10 pm, Robert Dailey <[EMAIL PROTECTED]> wrote: > Hi, > > I noticed in Python all function parameters seem to be passed by > reference. This means that when I modify the value of a variable of a > function, the value of the variable externally from the function is > also modified. Pyt

Re: Pass by reference or by value?

2007-07-13 Thread James Stroud
Erik Max Francis wrote: > James Stroud wrote: > >> Robert Dailey wrote: >> >>> I noticed in Python all function parameters seem to be passed by >>> reference. This means that when I modify the value of a variable of a >>> function, the value of the variable externally from the function is >>> also

Re: Pass by reference or by value?

2007-07-13 Thread Erik Max Francis
James Stroud wrote: > Robert Dailey wrote: >> I noticed in Python all function parameters seem to be passed by >> reference. This means that when I modify the value of a variable of a >> function, the value of the variable externally from the function is >> also modified. >> >> Sometimes I wish to

Re: Pass by reference or by value?

2007-07-13 Thread Bruno Desthuilliers
Robert Dailey a écrit : > On Jul 13, 2:10 pm, Robert Dailey <[EMAIL PROTECTED]> wrote: > >>Hi, >> >>I noticed in Python all function parameters seem to be passed by >>reference. (snip) > > Correction: > > I ran a few more tests and python actually does a pass by value, (snip) Still wrong !-)

Re: Pass by reference or by value?

2007-07-13 Thread Carsten Haese
. > and the external variable that was > passed in remains unchanged. That depends entirely on what kind of object the "variable" is and how you're trying to change the "variable." > I actually want to know how to "pass by > reference", in that an

Re: Pass by reference or by value?

2007-07-13 Thread star . public
On Jul 13, 3:10 pm, Robert Dailey <[EMAIL PROTECTED]> wrote: > Hi, > > I noticed in Python all function parameters seem to be passed by > reference. ... [And later otherwise, etc, snip] Heya. Go read through the thread from yesterday, title starts with "Understanding Python Functions" -- they go t

Re: Pass by reference or by value?

2007-07-13 Thread James Stroud
Robert Dailey wrote: > I actually want to know how to "pass by > reference", in that any changes made to a parameter inside of a > function also changes the variable passed in. Pass a mutable type. py> class C(object): ... def __repr__(self): ... return str(self.val

Re: Pass by reference or by value?

2007-07-13 Thread James Stroud
Robert Dailey wrote: > Hi, > > I noticed in Python all function parameters seem to be passed by > reference. This means that when I modify the value of a variable of a > function, the value of the variable externally from the function is > also modified. > > Sometimes I wish to work with "copies"

Re: Pass by reference or by value?

2007-07-13 Thread Robert Dailey
actually does a pass by value, meaning that a "copy" is made and the external variable that was passed in remains unchanged. I actually want to know how to "pass by reference", in that any changes made to a parameter inside of a function also changes the variable passed in. Thanks. -- http://mail.python.org/mailman/listinfo/python-list

Pass by reference or by value?

2007-07-13 Thread Robert Dailey
Hi, I noticed in Python all function parameters seem to be passed by reference. This means that when I modify the value of a variable of a function, the value of the variable externally from the function is also modified. Sometimes I wish to work with "copies", in that when I pass in an integer v