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(

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 >> responses, however I'm still confused on the topic. Note

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 topic. Note that I come from a > C++ bac

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
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? So if I were to create a class called Integer and give it a .set() method, this would allow me to create mutable integers, and thus passing in

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 > come from a C++ background to Python, so an

Re: Pass by reference or by value?

2007-07-16 Thread Steve Holden
Beliavsky wrote: > On Jul 13, 11:58 pm, sturlamolden <[EMAIL PROTECTED]> wrote: > > > >> In Fortran you can only pass references. >> >> integer(4) :: a >> a = 1 >> call bar(a) >> >> subroutine bar(a) >> integer(4) :: a >> a = 0 ! side-effect >> end subroutine >> >> That means, when a

Re: Pass by reference or by value?

2007-07-16 Thread Beliavsky
On Jul 13, 11:58 pm, sturlamolden <[EMAIL PROTECTED]> wrote: > In Fortran you can only pass references. > > integer(4) :: a > a = 1 > call bar(a) > > subroutine bar(a) > integer(4) :: a > a = 0 ! side-effect > end subroutine > > That means, when a variable is used to call a function,

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
[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.html http://effbot.org/zone/python-objects.htm In article <[EMAIL PROTECTE

Re: Pass by reference or by value?

2007-07-13 Thread sturlamolden
On Jul 13, 9:10 pm, Robert Dailey <[EMAIL PROTECTED]> 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. Pass-by-v

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
On Fri, 2007-07-13 at 19:22 +, Robert Dailey wrote: > Correction: > > I ran a few more tests and python actually does a pass by value, > meaning that a "copy" is made That is patently incorrect. A function call in Python *never* makes a copy of any of its arguments. > and the external varia

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.value) ... def __init__(se

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